GenerationJava.com's Simple-JNDISimple-JNDI is intended to solve two problems. The first is that of finding a container independent way of opening a database connection, the second is to find a good way of specifying application configurations. In a J2EE container, you can use JNDI as a java.sql.Connection factory. This code however is not usable outside of a J2EE container as you cannot guarrentee you have a JNDI implementation available, and to be honest, you don't want to start some other server to make your simple script run. Simple-JNDI is not a server, it is merely an API, however it looks exactly the same as the JNDI client code used in a J2EE container. Applications need configuration. A servlets container uses the web.xml files to configure, while a J2EE container uses a different system, for example, JBoss has a jboss.jcml configuration file which sets a system up via JMX managed beans. An application could however use Simple-JNDI for parameter values. Using Simple-JNDIUsing Simple-JNDI is the same as using JNDI itself. So this is not covered here, however the examples do give the basic gist. Installing Simple-JNDIInstalling Simple-JNDI is as simple as adding the simple-jndi jar, jdbc 2.0 jar and the commons-lang jar to your classpath. Setting up Simple-JNDIThis is where all the work goes in a Simple-JNDI installation. Firstly you need a jndi.properties file, which somehow needs to go into your classpath. This jndi.properties needs one manadatory value:
java.naming.factory.initial=com.generationjava.jndi.PropertiesFactory
This property is a part of the jndi specification, java.naming.factory.initial. This should be set equal to com.generationjava.jndi.PropertiesFactory.
There are two optional, simple-jndi specific parameters.
# absolute directory, using the default file protocol
If no com.generationjava.jndi.root is specified, then a classpath root is chosen, with no package. The second optional parameter is the delimiter used to separate elements in a lookup value. This allows code to get closer to pretending to be another JNDI implementation, such as DNS or LDAP.
# DNS/Java like delimiters
If no com.generationjava.jndi.delimiter is specified, then a '.' (dot) is chosen. |