初期コンテキストは、JMS キューなどのオブジェクトを検索できるJNDI名前空間への参照です。少し前にこのチュートリアルを書いたので、参考になるかもしれません。
リモートjboss サーバーの場合、これが必要な 3 つの基本があります (デフォルト ポートを使用):
- java.naming.factory.initial : org.jnp.interfaces.NamingContextFactory
- java.naming.factory.url.pkgs : org.jboss.naming:org.jnp.interfaces
- java.naming.provider.url : <ホスト名>:1099
コードは次のようになります。
import javax.naming.*;
import javax.jms.*;
import java.util.*;
.....
Properties jndiProps = new Properties();
jndiProps.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
jndiProps.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
jndiProps.put("java.naming.provider.url", "localhost:1099");
Context ctx = new InitialContext(jndiProps);
Queue jmsQueue = (Queue)ctx.lookup("jndi-name-of-queue");
コードがjboss サーバー内で実行されている場合、これらのプロパティは暗黙的であるため必要ありません。
import javax.naming.*;
import javax.jms.*;
.....
Context ctx = new InitialContext(); // no properties needed
Queue jmsQueue = (Queue)ctx.lookup("jndi-name-of-queue");