MoinMoin Logo
  • Comments
  • Immutable Page
  • Menu
    • Navigation
    • RecentChanges
    • FindPage
    • Local Site Map
    • Help
    • HelpContents
    • HelpOnMoinWikiSyntax
    • Display
    • Attachments
    • Info
    • Raw Text
    • Print View
    • Edit
    • Load
    • Save
  • Login

Navigation

  • Start
  • Sitemap
Revision 2 as of 2014-06-10 21:50:17
  • Java
  • JNDI

JNDI

JNDI is a standard Java API that is bundled with JDK1.3 and higher. JNDI provides a common interface to a variety of existing naming services: DNS, LDAP, Active Directory, RMI registry, COS registry, NIS, and file systems.

http://docs.jboss.org/jbossas/jboss4guide/r1/html/ch3.chapter.html

http://stackoverflow.com/questions/13643127/how-does-the-ejb-client-locate-the-ejb-server-without-url

Sample

Properties:

  • java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory

  • java.naming.provider.url=jnp://localhost:1099
  • java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

File test/Client.java

   1 package test;
   2 import java.security.Security;
   3 import java.util.Properties;
   4 import javax.naming.Context;
   5 import javax.naming.InitialContext;
   6 import org.allowed.bitarus.IWSTest;
   7                     
   8 public class Client
   9 {
  10     public static void main(String args[]) throws Exception
  11     {
  12         Properties env = new Properties();
  13         env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
  14         env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
  15         env.put(Context.PROVIDER_URL, "jnp://127.0.0.1:1099");
  16         InitialContext context = new InitialContext(env);
  17         IWSTest test = (IWSTest) context.lookup("WSTest/remote");
  18         System.out.println( test.helloWorld() );
  19     }
  20 }

Build:

  • cd test #package folder
  • javac -cp .:test2-0.0.1.jar Client.java

Run:

  • java -cp .:/opt/jboss-5.1.0.GA/client/*:test/test2-0.0.1.jar test/Client # JBoss client Jars, EJB with interface IWSTest
  • MoinMoin Powered
  • Python Powered
  • GPL licensed
  • Valid HTML 4.01