Question

I need to run a JNDI provider without the overhead of a J2EE container. I've tried to follow the directions in this article, which describes (on page 3) exactly what I want to do. Unfortunately, these directions fail. I had to add the jboss-common.jar to my classpath too. Once I did that, I get a stack trace:

$ java org.jnp.server.Main
0    [main] DEBUG
org.jboss.naming.Naming  - Creating
NamingServer stub, theServer=null,rmiPort=0,clientSocketFactory=null,serverSocketFactory=org.jboss.net.sockets.DefaultSocketFactory@ad093076[bindAddress=null]
Exception in thread "main"
java.lang.NullPointerException
     at org.jnp.server.Main.getNamingInstance(Main.java:301)
     at org.jnp.server.Main.initJnpInvoker(Main.java:354)
     at org.jnp.server.Main.start(Main.java:316)
     at org.jnp.server.Main.main(Main.java:104)

I'm hoping to make this work, but I would also be open to other lightweight standalone JNDI providers. All of this is to make ActiveMQ work, and if somebody can suggest another lightweight JMS provider that works well outside of the vm the clients are in without a full blown app server that would work too.

Was it helpful?

Solution

Apache ActiveMQ already comes with an integrated lightweight JNDI provider. See these instructions on using it.

Basically you just add the jndi.properties file to the classpath and you're done.

java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory

# use the following property to configure the default connector
java.naming.provider.url = failover:tcp://localhost:61616

# use the following property to specify the JNDI name the connection factory
# should appear as. 
#connectionFactoryNames = connectionFactory, queueConnectionFactory, topicConnectionFactry

# register some queues in JNDI using the form
# queue.[jndiName] = [physicalName]
queue.MyQueue = example.MyQueue


# register some topics in JNDI using the form
# topic.[jndiName] = [physicalName]
topic.MyTopic = example.MyTopic

OTHER TIPS

Use a jndi.properties file like this:

java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory

# use the following property to configure the default connector
java.naming.provider.url=tcp://jmshost:61616

# use the following property to specify the JNDI name the connection factory
# should appear as. 
#connectionFactoryNames = connectionFactory, queueConnectionFactory, topicConnectionFactry

# register some queues in JNDI using the form
# queue.[jndiName] = [physicalName]
#queue.MyQueue = example.MyQueue


# register some topics in JNDI using the form
# topic.[jndiName] = [physicalName]
topic.myTopic = MY.TOPIC

Make sure that this file is in your classpath. Then you can lookup the topic/queue like this (minus appropriate try/catches):

context = new InitialContext(properties);

context = (Context) context.lookup("java:comp/env/jms");

topicConnectionFactory = (TopicConnectionFactory) context.lookup("ConnectionFactory");

topic = (Topic) context.lookup("myTopic");

The JBoss JMQ can also be run with just the MicroKernel and a very minimal set of libraries. The JBoss AS installer has options for "profiles" one of which is for a standalone JMQ. It also allows you to pick and choose components (though it doesn't help you with dependencies too much). Have you tried running the installer?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top