## page was renamed from 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 
{{{#!highlight java
package test;
import java.security.Security;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import org.allowed.bitarus.IWSTest;
                    
public class Client
{
    public static void main(String args[]) throws Exception
    {
        Properties env = new Properties();
        env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
        env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
        env.put(Context.PROVIDER_URL, "jnp://127.0.0.1:1099");
        InitialContext context = new InitialContext(env);
        IWSTest test = (IWSTest) context.lookup("WSTest/remote");
        System.out.println( test.helloWorld() );
    }
}

}}}

Build:  
{{{#!highlight sh
cd test #package folder
javac  -cp .:test2-0.0.1.jar Client.java 
}}}

Run:
{{{#!highlight sh
java -cp .:/opt/jboss-5.1.0.GA/client/*:test/test2-0.0.1.jar test/Client # JBoss client Jars, EJB with interface IWSTest
}}}

== Maven sample ==
Structure
{{{
.
|-- pom.xml
|-- src
|   `-- main
|       `-- java
|           `-- org
|               `-- allowed
|                   `-- bitarus
|                       `-- ejbclient
|                           `-- Client.java
`-- target
    |-- classes
    |   `-- org
    |       `-- allowed
    |           `-- bitarus
    |               `-- ejbclient
    |                   `-- Client.class
    |-- ejbclient-1.0.jar
    |-- maven-archiver
    |   `-- pom.properties
    `-- surefire
}}}

Content pom.xml
{{{#!highlight xml
<project xmlns="http://maven.apache.org/POM/4.0.0" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
	http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.allowed.bitarus</groupId>
  <artifactId>ejbclient</artifactId>
  <packaging>jar</packaging>
  <version>1.0</version>
  <name>ejbclient</name>
  <url>http://maven.apache.org</url>
  <!-- 
       mkdir -p src/main/java/org/allowed/bitarus/ejbclient 
       mvn clean compile package
       java -classpath "/opt/jboss-5.1.0.GA/client/*:target/ejbclient-1.0.jar:/tmp/test2/target/test2-0.0.1.jar" org.allowed.bitarus.ejbclient.Client
  -->
  <build>
    <plugins>
      <plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-jar-plugin</artifactId>
	<version>2.4</version>
	<configuration>
	  <archive>
	    <manifest>
	      <mainClass>org.allowed.bitarus.ejbclient.Client</mainClass>
	    </manifest>
	  </archive>
	</configuration>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
      <groupId>org.allowed.bitarus</groupId>
      <artifactId>test2</artifactId>
      <version>0.0.1</version>
    </dependency>
  </dependencies>  
</project>
}}}

Content Client.java
{{{#!highlight java
package org.allowed.bitarus.ejbclient;
import java.security.Security;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import org.allowed.bitarus.IWSTest;
                    
public class Client
{
    public static void main(String args[]) throws Exception
    {
        Properties env = new Properties();
        env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
        env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
        env.put(Context.PROVIDER_URL, "jnp://127.0.0.1:1099");
        InitialContext context = new InitialContext(env);
        IWSTest test = (IWSTest) context.lookup("WSTest/remote");
        System.out.println( test.helloWorld() );
    }
}
}}}

Maven steps:
{{{#!highlight sh
mvn clean compile package
}}}

Run program:
{{{#!highlight sh
java -classpath "/opt/jboss-5.1.0.GA/client/*:target/ejbclient-1.0.jar:/tmp/test2/target/test2-0.0.1.jar" org.allowed.bitarus.ejbclient.Client
}}}