2015-06-15 5 views
0

Я пытаюсь создать простой JAR, который публикует сообщение в очереди в HornetQ и запускает JAR из Eclipse. Я получаю следующую ошибку. Я предполагаю, что это связано с версиями сборки, но я не уверен, как его отслеживать.ClassNotFoundException, когда клиент подключается к HornetQ

javax.naming.NamingException: Failed to lookup [Root exception is java.io.IOException: java.lang.ClassNotFoundException: org.hornetq.core.client.impl.AfterConnectInternalListener] 
    at org.jboss.naming.remote.client.ClientUtil.namingException(ClientUtil.java:36) 
    at org.jboss.naming.remote.protocol.v1.Protocol$1.execute(Protocol.java:101) 
    at org.jboss.naming.remote.protocol.v1.RemoteNamingStoreV1.lookup(RemoteNamingStoreV1.java:76) 
    at org.jboss.naming.remote.client.RemoteContext.lookup(RemoteContext.java:77) 
    at org.jboss.naming.remote.client.RemoteContext.lookup(RemoteContext.java:81) 
    at javax.naming.InitialContext.lookup(Unknown Source) 
    at com.me.joel.MessageCreator.createMessage(MessageCreator.java:20) 
    at com.me.joel.MessageProducerJar.main(MessageProducerJar.java:9) 
Caused by: java.io.IOException: java.lang.ClassNotFoundException: org.hornetq.core.client.impl.AfterConnectInternalListener 
    at org.jboss.naming.remote.protocol.v1.Protocol$1$3.read(Protocol.java:156) 
    at org.jboss.naming.remote.protocol.v1.BaseProtocolCommand.readResult(BaseProtocolCommand.java:60) 
    at org.jboss.naming.remote.protocol.v1.Protocol$1.handleClientMessage(Protocol.java:146) 
    at org.jboss.naming.remote.protocol.v1.RemoteNamingStoreV1$MessageReceiver$1.run(RemoteNamingStoreV1.java:184) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
    at java.lang.Thread.run(Unknown Source) 
Caused by: java.lang.ClassNotFoundException: org.hornetq.core.client.impl.AfterConnectInternalListener 
    at java.net.URLClassLoader$1.run(Unknown Source) 
    at java.net.URLClassLoader$1.run(Unknown Source) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.net.URLClassLoader.findClass(Unknown Source) 
    at java.lang.ClassLoader.loadClass(Unknown Source) 
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) 
    at java.lang.ClassLoader.loadClass(Unknown Source) 
    at java.lang.Class.forName0(Native Method) 
    at java.lang.Class.forName(Unknown Source) 
    at org.jboss.marshalling.AbstractClassResolver.loadClass(AbstractClassResolver.java:135) 
    at org.jboss.marshalling.AbstractClassResolver.resolveClass(AbstractClassResolver.java:116) 
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadClassDescriptor(RiverUnmarshaller.java:870) 
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadClassDescriptor(RiverUnmarshaller.java:902) 
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1204) 
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:272) 
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:209) 
    at org.jboss.marshalling.river.RiverUnmarshaller.readFields(RiverUnmarshaller.java:1677) 
    at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1593) 
    at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1557) 
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1235) 
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:272) 
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:209) 
    at org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:37) 
    at org.jboss.naming.remote.protocol.v1.Protocol$1$3.read(Protocol.java:153) 
    ... 6 more 

Это мой код:

public void createMessage() throws Exception{ 
     String destinationName = "queue/test"; 

     Context ic = null; 
     ConnectionFactory cf = null; 
     Connection connection = null; 

     try {   
      ic = getInitialContext(); 

      cf = (ConnectionFactory)ic.lookup("jms/RemoteConnectionFactory"); 
      //Topic topic = (Topic)ic.lookup(destinationName); 
      Queue objQueue = (Queue)ic.lookup(destinationName); 

      connection = cf.createConnection(); 
      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 
      MessageProducer publisher = session.createProducer(objQueue); 
      //MessageConsumer subscriber = session.createConsumer(topic); 

      //subscriber.setMessageListener(this); 
      connection.start(); 

      TextMessage message = session.createTextMessage("Hello!"); 
      publisher.send(message); 

      //Scanner keyIn = new Scanner(System.in); 

      //System.out.print("JMS Server listening. Type a Key + CR to exit\n"); 
      //keyIn.next(); 

     } 
     finally 
     { 
      if(ic != null) 
      { 
       try 
       { 
        ic.close(); 
       } 
       catch(Exception e) { 
        throw e; 
       } 
      } 

      closeConnection(connection); 
     } 
    } 

    public static Context getInitialContext() throws javax.naming.NamingException { 

     Properties p = new Properties(); 
     p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory"); 
     //p.put(Context.URL_PKG_PREFIXES," org.jboss.naming:org.jnp.interfaces"); 
     p.put(Context.PROVIDER_URL, "remote://localhost:4447"); 
     p.put(Context.SECURITY_PRINCIPAL, "user"); 
     p.put(Context.SECURITY_CREDENTIALS, "password"); 
     return new javax.naming.InitialContext(p); 
     //return new javax.naming.InitialContext(); 
    } 

И мои зависимости POM

<dependencies> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>3.8.1</version> 
     <scope>test</scope> 
    </dependency> 
    <!-- <dependency> 
     <groupId>org.hornetq</groupId> 
     <artifactId>hornetq-core</artifactId> 
     <version>2.2.6.Final</version> 
     <scope>provided</scope> 
    </dependency> --> 
    <dependency> 
     <groupId>org.hornetq</groupId> 
     <artifactId>hornetq-core-client</artifactId> 
     <version>2.2.6.Final</version> 
     <scope>provided</scope> 
    </dependency> 
    <!-- <dependency> 
     <groupId>org.hornetq</groupId> 
     <artifactId>hornetq-jms</artifactId> 
     <version>2.2.18.Final</version> 
     <scope>provided</scope> 
    </dependency> --> 
    <dependency> 
     <groupId>org.hornetq</groupId> 
     <artifactId>hornetq-jms-client</artifactId> 
     <version>2.2.18.Final</version> 
    </dependency> 
    <dependency> 
     <groupId>org.hornetq</groupId> 
     <artifactId>hornetq-jms-client</artifactId> 
     <version>2.2.6.Final</version> 
     <scope>provided</scope> 
    </dependency> 
    <!-- <dependency> 
     <groupId>org.hornetq</groupId> 
     <artifactId>hornetq-logging</artifactId> 
     <version>2.2.6.Final</version> 
     <scope>provided</scope> 
    </dependency> --> 
    <dependency> 
     <groupId>org.hornetq.rest</groupId> 
     <artifactId>hornetq-rest</artifactId> 
     <version>2.2.2.Final</version> 
    </dependency> 
    <!-- <dependency> 
     <groupId>org.hornetq</groupId> 
     <artifactId>hornetq-transports</artifactId> 
     <version>2.1.0</version> 
     <scope>compile</scope> 
    </dependency> --> 
<!-- <dependency> 
     <groupId>org.jboss.netty</groupId> 
     <artifactId>netty</artifactId> 
     <version>3.1.0.GA</version> 
    </dependency> --> 
    <dependency> 
     <groupId>log4j</groupId> 
     <artifactId>log4j</artifactId> 
     <version>1.2.16</version> 
     <exclusions> 
      <exclusion> 
       <groupId>javax.mail</groupId> 
       <artifactId>mail</artifactId> 
      </exclusion> 
      <exclusion> 
       <groupId>javax.jms</groupId> 
       <artifactId>jms</artifactId> 
      </exclusion> 
      <exclusion> 
       <groupId>com.sun.jdmk</groupId> 
       <artifactId>jmxtools</artifactId> 
      </exclusion> 
      <exclusion> 
       <groupId>com.sun.jmx</groupId> 
       <artifactId>jmxri</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 
    <dependency> 
     <groupId>org.jboss.javaee</groupId> 
     <artifactId>jboss-jms-api</artifactId> 
     <version>1.1.0.GA</version> 
     <scope>compile</scope> 
    </dependency> 

    <dependency> 
     <groupId>org.jboss.as</groupId> 
     <artifactId>jboss-as-ejb-client-bom</artifactId> 
     <version>7.1.0.Final</version> 
     <type>pom</type> 
     <scope>compile</scope> 
    </dependency> 
    <!-- 
    <dependency> 
    <groupId>org.hornetq</groupId> 
    <artifactId>hornetq-core</artifactId> 
    <version>2.0.0.GA</version> 
    <scope>compile</scope> 
    </dependency> 
    <dependency> 
    <groupId>org.hornetq</groupId> 
    <artifactId>hornetq-core-client</artifactId> 
    <version>2.0.0.GA</version> 
    <scope>compile</scope> 
</dependency> 
    <dependency> 
    <groupId>org.hornetq</groupId> 
    <artifactId>hornetq-jms</artifactId> 
    <version>2.0.0.GA</version> 
    <scope>compile</scope> 
    </dependency> 
<dependency> 
    <groupId>org.hornetq</groupId> 
    <artifactId>hornetq-jms-client</artifactId> 
    <version>2.0.0.GA</version> 
    <scope>compile</scope> 
</dependency> 
<dependency> 
    <groupId>org.hornetq</groupId> 
    <artifactId>hornetq-transports</artifactId> 
    <version>2.0.0.GA</version> 
    <scope>compile</scope> 
</dependency> 
<dependency> 
    <groupId>org.jboss.netty</groupId> 
    <artifactId>netty</artifactId> 
    <version>3.1.0.GA</version> 
</dependency> --> 
<dependency> 
    <groupId>org.jboss.javaee</groupId> 
    <artifactId>jboss-jms-api</artifactId> 
    <version>1.1.0.GA</version> 
    <scope>compile</scope> 
</dependency> 
    </dependencies> 

ответ

0

Вы только что упомянули, что hornetq-ядро-клиент Lib предоставляется:

<dependency> 
    <groupId>org.hornetq</groupId> 
    <artifactId>hornetq-core-client</artifactId> 
    <version>2.2.6.Final</version> 
    <scope>provided</scope> 
</dependency> 

Что, очевидно, нет, и из-за этого лет u получить ClassNotFoundException на org.hornetq.core.client.impl.AfterConnectInternalListener.

+0

Области, размещенные как скопированные из другого приложения, которое работает. FWIW, это приложение построено как WAR, но оно имеет множество классов с основными методами, которые я могу использовать для тестирования через Eclipse. Я просто попытался изменить hornetq-core-client для компиляции, а также как hornetq-core-client, так и hornetq-jms-client, и каждый раз получаю одинаковые результаты. – joelt

+0

Пожалуйста, объясните, как выполняются ваши тесты. Я имею в виду, как в затмении вы запускаете свой тест. Поскольку я думаю, что jboss предоставляет hornetq, и я предполагаю, что другое приложение было запущено на jboss, но вы не проверяете свой код на jboss. –

+0

В случае этого JAR он имеет класс с методом Main. Когда я нахожусь в исходном файле этого класса, на панели инструментов есть зеленая кнопка «Воспроизвести» с параметрами «Запускать как»> «Приложение Java». Это приводит к исключению выше. В случае с файлом WAR, о котором я упоминал, сама WAR предназначена для развертывания в JBOSS, да. Тем не менее, в src/test/java также есть набор классов. Каждый из этих классов имеет основной метод, поэтому, если я открою исходный файл, я получаю одну и ту же зеленую кнопку «играть», и я могу запустить тестовый класс как приложение Java. Подробнее ... – joelt