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
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