views:

2685

answers:

3

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.

+1  A: 

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?

Steve Moyer
That's a good suggestion, but I really need to get away from JBoss if at all possible. If I can't get away from it, I'll definitely pare it down as much as possible like you suggested.
Benson
+1  A: 

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");
KC Baltz
Note the JNDI provider you are using is not Simple JNDI - but the JNDI provicder that comes with ActiveMQ :). See the class name of the *java.naming.factory.initial* entry :)
James Strachan
Wow, you're right. I thought that simple-jndi was making that work. We had it in the project already for JDBC DataSource lookups. I've corrected my entry.
KC Baltz
+3  A: 

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
James Strachan
This doesn't seem to cover the fact that we need a TCP JNDI provider. Unless I'm quite mistaken, VM endpoints don't work across VMs. I need to be able to run separate processes that talk via JNDI. Is that possible with this JNDI provider?
Benson
Sorry - cut and paste issue. I've just updated the *java.naming.provider.url* entry so it uses TCP - and uses failover which you should use by default to reconnect if a socket fails or a broker is bounced
James Strachan
Great, thanks. I'll have to try this out and see if it works for me.
Benson