Installing Simple-JNDI

After download, installing Simple-JNDI is as simple as adding the simple-jndi jar to your classpath. Some of the features do however need additional dependencies. To get connection-pooling you will need commons-dbcp, which needs commons-pool and commons-collections. All are linked from the download page.

Setting up Simple-JNDI

This 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 mandatory value:

java.naming.factory.initial=org.osjava.sj.SimpleContextFactory

This property, java.naming.factory.initial, is a part of the jndi specification.

There are two simple-jndi specific parameters.

The first (required) parameter, org.osjava.sj.root, is the location of your simple-jndi root, which is the location in which simple-jndi looks for values when code asks for them. The following code block details a few examples with explanatory comments.

# absolute directory, using the default file protocol
org.osjava.sj.root=/home/hen/gj/simple-jndi/config/

# relative directory, using the default file protocol
org.osjava.sj.root=config/

# specified file protocol with an absolute directory
org.osjava.sj.root=file:///home/hen/gj/simple-jndi/config/

# specified file protocol with a relative directory
org.osjava.sj.root=file://config/

If no org.osjava.sj.root is specified, an Exception is thrown. When classpath support is re-implemented, then a classpath root will be 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
org.osjava.sj.delimiter=.

# LDAP/XPath like delimiters
org.osjava.sj.delimiter=/

If no org.osjava.sj.delimiter is specified, then a '.' (dot) is chosen.

Memory implementation configuration

Setting org.osjava.sj.jndi.shared=true will put the in-memory JNDI implementation into a mode whereby all InitialContext's share the same memory. By default this is not set, so two separate InitialContext's do not share the same memory and what is bound to one will not be viewable in the other.

Dealing with java: while loading

Windows does not like having a : in a filename, so to deal with the : you can use the org.osjava.sj.colon.replace property. If, for example, you choose to replace a : with -- (ie org.osjava.sj.colon.replace=--), then you will need a file named java--.properties, or a directory named java--. Alternatively, the next section provides a different way of handling things.

Dealing with ENCs while loading

To simulate an environment naming context (ENC), the org.osjava.sj.space property may be used. Whatever the property is set to will be automatically prepended to every value loaded into the system. Thus org.osjava.sj.space=java:/comp/env simulates the JNDI environment of Tomcat.

As : is usually found in an ENC, using this property to handle ENCs is a simpler way to handle the colon than using the colon-replace property.