Configuring with Maven2

  1. Add simple-jndi dependency to pom.xml:
      <dependency>
        <groupId>simple-jndi</groupId>
        <artifactId>simple-jndi</artifactId>
        <version>0.11.1</version>
        <scope>test</scope>
      </dependency>
      
  2. Add your jdbc driver dependency with test to pom.xml
  3. Tell the JVM to use simple-jndi by creating jndi.properties in the test resource directory. By default the directory is src/test/resources. The file jndi.properties contains the following lines. The properties org.osjava.sj.colon.replace and org.osjava.sj.delimiter are used in this example because the application being tested will run on Tomcat on Windows.
      java.naming.factory.initial=org.osjava.sj.SimpleContextFactory
      org.osjava.sj.root=src/test/resources/simple-jndi
      org.osjava.sj.colon.replace=--
      org.osjava.sj.delimiter=/
    
  4. Create the files to define the JNDI datasource myDataSource. Please note the directory below is in the directory defined by os.java.js.root.
         /java--comp
           /env
             default.properties
        
    default.properties contains the following:
      myDataSource/type=javax.sql.DataSource
      myDataSource/driver=<jdbc driver class>
      myDataSource/url=<jdbc url>
      myDataSource/user=foo
      myDataSource/password=bar