为什么Websocket / JMS企业项目抛出ClassNotFoundException javax.jms.Destination

时间:2018-12-20 00:06:04

标签: java websocket wildfly-10

已编辑12/20

Oracal要求我将一个WebStart / JMS / Java-Swing-Client企业项目改制成Websockets。/

因此,我通过在以下Blog中实现JMS / Websockets示例并将项目作为EAR文件部署到Wildfly 10服务器上来开始学习。

[https://blogs.oracle.com/theaquarium/integrating-websockets-and-jms-with-cdi-events-in-java-ee-7-v2][1]

我的项目编译正常。 ANT构建文件将其打包到耳朵文件中。

但是当我在Wildfly10上自动部署Ear文件时,它会抛出一个

ClassNotFoundException javax.jms.Destination

但是我读到,当用standalone-full.xml启动Wildfly时,它将使用JMS API进行配置。而且我绝对从standalone-full.xml开始。

这听起来有些矫kill过正,但是我无法弄清楚如何仅用片段来充分解释问题,因此我在下面粘贴了完整的项目代码,因此,如果没有其他事情,使其起作用可能对其他面临的问题有价值Webstart的Oracal关闭。

这是下面粘贴的代码的列表。

A:课程:

B:构建路径中的所有jar。

C:application.xml和web.xml

D:耳朵文件的结构。(我没有在下面粘贴它,但是我有用于打包项目的ANT构建文件。

E:HTML Websocket客户端。

详细信息

A:班

EndPointOne.java

package org.america3.websockets.endpoints;
import java.io.Serializable;
import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;
import org.america3.websockets.javabeans.WebsocketJMSMsg;
import org.america3.websockets.javabeans.WebsocketSenderBean;
import javax.inject.Named;
import javax.websocket.OnClose;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.enterprise.event.Observes;
import javax.inject.Inject;
@Named
@ServerEndpoint("/websocket") 
public class EndpointOne implements Serializable {
  //class members
  private              WebsocketSenderBean senderBean;
  private static final Set<Session> sessions = Collections.synchronizedSet(new HashSet<Session>()); 

  // Constructor
  @Inject
  public EndpointOne(WebsocketSenderBean sb) {
    this.senderBean = sb;
  }

  //Methods
  @OnOpen
  public void onOpen(final Session session) {
    sessions.add(session); 
  } 

  @OnMessage 
  public void onMessage(final String message, final Session client) {
    senderBean.sendMessage(message); 
  } 

  @OnClose 
  public void onClose(final Session session) {
    sessions.remove(session); 
  }
  public void onJMSMessage(@Observes @WebsocketJMSMsg Message msg) {
    try {
      for (Session s : sessions) {
        s.getBasicRemote().sendText("message from JMS: " + msg.getBody(String.class));}
    } catch (IOException | JMSException ex) {
      Logger.getLogger(EndpointOne.class.getName()).log(Level.SEVERE, null, ex);}
  } 
}

WebsocketMDB.java

package org.america3.websockets.javabeans;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.io.IOException;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.websocket.Session;
import org.america3.websockets.endpoints.EndpointOne;
import javax.ejb.MessageDriven;
import javax.inject.Named;
import javax.inject.Qualifier;
import javax.inject.Inject;
import javax.enterprise.event.Event;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.enterprise.event.Observes;

@Named
@MessageDriven(mappedName = "/jms/queue/listenToWSClientQueue")
public class WebsocketMDB implements MessageListener {
  //Class Members
  @Inject
  @WebsocketJMSMsg
  Event<Message> jmsEvent;
  private static final Set<Session> sessions 
  = Collections.synchronizedSet(new HashSet<Session>()); 

  //Methods
  @Override
  public void onMessage(Message msg) { 
    jmsEvent.fire(msg);   
  }
}

WebsocketSenderBean.java
package org.america3.websockets.javabeans;
import javax.inject.Named;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.annotation.Resource;
import javax.jms.Queue;
import javax.inject.Inject;
import javax.jms.JMSContext;

@Named
@LocalBean
@Stateless 
public class WebsocketSenderBean {
  //Class members
  @Resource(mappedName = "jms/queue/sendToWSClientQueue")
  private Queue sendQueue;
  @Inject private JMSContext jmsContext;

  //Class methods
  public void sendMessage(String message) {
    jmsContext.createProducer().send(sendQueue, message);
  }
}

WebsocketJMSMsg.java

package org.america3.websockets.javabeans;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;

@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE})
public @interface WebsocketJMSMsg {
/***************************************/
/* This seems an important part of the */
/* project. I think it must be used to */
/* swap Websockt <-> Java Bean messages*/
}

B:构建路径jar文件。

C:\Program Files\Java\jre1.8.0_191
cdi-api-1.1.jar    
javax.jms-api-2.0.jar
javax.websocket-api-1.1.jar
javax-inject.jar
javax.jms-3.1.2.2.jar

C:XML配置文件

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>
</web-app>

application.xml

<?xml version="1.0" encoding="UTF-8"?>  
  <application  
    xmlns="http://java.sun.com/xml/ns/j2ee"  
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd"  
    version="1.4">  

    <description>GoTest</description>  
    <display-name>WebsocketOne</display-name>

    <!--  Declare the server-side jar file as an ejb modules  -->  
    <module>  
      <ejb>WebsocketJMS-server.jar</ejb>  
    </module>  

    <module id="WebOne">
    <web>
      <web-uri>WebsocketJMS-war.war</web-uri>
      <context-root>/WSTEST</context-root>
    </web>

  </module>
  </application>

D:耳朵的包装结构

EAR FILE (WebsocketJMS.ear)
    META-INF
        MANIFEST.MF
        application.xml
    SERVER SIDE CLASS JAR (WebsocketsJMS-server.jar)
        META-INF
            MANIFEST.MF
        org.america3.websockets.endpoints 
            EndpointOne.java    
        org.america3.websockets.javabeans  
            WebsocketJMSMsg.java        
            WebsocketMDB.java           
            WebsocketSenderBean.java
    WAR Archive (WebsocketsJMS-war.war)
        WEB-INF
            MANIFEST.MF
            web.xml
    index.html

0 个答案:

没有答案