実際、私はJBoss 4を使用していますが、JNDIの使用は難しくありません。
まず、JNDIが実行されている場所を知る必要があります。
私のJBoss(conf \ jboss-service.xml)には次のものがあります。
<mbean code="org.jboss.naming.NamingService" name="jboss:service=Naming" xmbean-dd="resource:xmdesc/NamingService-xmbean.xml">
...
<attribute name="Port">7099</attribute>
...
</mbean>
これは重要です。これは接続したいポートです。
これで、次のコードを使用してJNDIに簡単に接続できます。
Hashtable<String, String> contextProperties = new Hashtable<String, String>();
contextProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
contextProperties.put(Context.PROVIDER_URL, "jnp://localhost:7099");
InitialContext initContext = new InitialContext(contextProperties);
コンテキストがある場合、接続ファクトリの作成を除いて、@ Nick Holtの回答と非常によく似ていますが、次を使用する必要があります。
QueueConnectionFactory connFactory = (QueueConnectionFactory) initContext.lookup("ConnectionFactory");
また、いくつかがデプロイされている場合は、キューを作成する必要はありません
Queue queue = (Queue) initContext.lookup("queueName");
上記のすべてのコードは、JBoss 4.2.2 GAおよびJBossMQでテストされました(JBossMQは、私が正しければ、4.2.3でJBossメッセージングに置き換えられました)。