key 发表于 2-10-2009 16:46:55

Redistribution JNP Server: Standalone Naming Service From JBoss 3.2.7

I need JNDI service for my server-side application running without J2EE
platform. I chose JND Server from JBoss, which was introduced here:

http://www.javaworld.com/javaworld/jw-04-2002/jw-0419-jndi.html?page=1

However, the article above was posted in 2002. There are some incompatible
issues for the newer version of JBoss. Now I extracted the JNP Server from
JBoss 3.2.7, the lowest stable version I can find from the official website.

Usage
1. Make sure you've install JRE and ANT, and set the environment variables
such as PATH and JAVA_HOME properly.
2. Uncompress my ZIP file into a directory, e.g. /opt/jnpserver-3.2.7 in Linux
or C:\tools\jnpserver-3.2.7
3. Change to the directory
4. Run ant
$ant

That's all.
You will get a standalone JNDI service running at port 1099.

[ 本帖最后由 key 于 2-10-2009 16:50 编辑 ]

key 发表于 2-10-2009 17:05:11

Test Case for the JNP Server

import javax.naming.Context;
import javax.naming.InitialContext;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

/**
*
* @author key - freeoz
*/
public class SimpleTest {
    private static int testValue;

    public SimpleTest() {
    }

    @BeforeClass
    public static void setUpClass() throws Exception {
      System.setProperty("java.naming.provider.url", "localhost:1099");
      System.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
      System.setProperty("java.naming.factory.url", "jnp://www.jboss.org:1099");
      testValue = (int)(Math.random() * 0xFFFFFF);
    }

    @AfterClass
    public static void tearDownClass() throws Exception {
    }

    @Before
    public void setUp() {
    }

    @After
    public void tearDown() {
    }


    @Test
    public void initJndi() throws Exception{
      Context ctx = new InitialContext();
      System.out.println("Bind test value " + testValue + " to JNDI service");
      ctx.bind("TestValue", testValue);
      ctx.close();      
    }

    @Test
    public void testJndi() throws Exception {
      Context ctx = new InitialContext();
      Integer v = (Integer)ctx.lookup("TestValue");
      System.out.println("Retrieve value = " + v);
      ctx.close();
    }
}
页: [1]
查看完整版本: Redistribution JNP Server: Standalone Naming Service From JBoss 3.2.7