代码之家  ›  专栏  ›  技术社区  ›  Benson

不带J2EE容器的JNDI(带JNP?可能是其他供应商?)

  •  5
  • Benson  · 技术社区  · 16 年前

    我需要运行一个JNDI提供程序,而不需要J2EE容器的开销。我试着按这个方向走 article (第3页)正是我想要做的。不幸的是,这些方向失败了。我还必须将jboss-common.jar添加到类路径中。一旦我这样做了,我会得到一个堆栈跟踪:

    $ 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)
    

    我希望能实现这一点,但是我也愿意向其他轻量级的独立JNDI提供者开放。所有这些都是为了让ActiveMQ工作,如果有人可以建议另一个在虚拟机之外工作良好的轻量级JMS提供程序,那么客户机就不需要一个完全可以工作的应用服务器。

    3 回复  |  直到 16 年前
        1
  •  6
  •   James Strachan    16 年前

    Apache ActiveMQ 已经有了一个集成的轻量级JNDI提供程序。见 these instructions on using it .

    基本上,只需将jndi.properties文件添加到类路径,就可以完成。

    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
    
        2
  •  2
  •   community wiki 3 revs KC Baltz    16 年前

    使用jndi.properties文件,如下所示:

    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
    

    确保此文件在类路径中。然后您可以这样查找主题/队列(减去适当的try/catch):

    context = new InitialContext(properties);
    
    context = (Context) context.lookup("java:comp/env/jms");
    
    topicConnectionFactory = (TopicConnectionFactory) context.lookup("ConnectionFactory");
    
    topic = (Topic) context.lookup("myTopic");
    
        3
  •  1
  •   Steve Moyer    16 年前

    JBossJMQ也可以只使用微内核和非常少的一组库来运行。jboss as安装程序有“profiles”选项,其中一个选项用于独立的jmq。它还允许您选择和选择组件(尽管它对依赖性没有太多帮助)。你试过运行安装程序吗?