这是我第一次尝试使用JMS。我有一个成功创建/部署的war文件,其中包含一个可用于上传文件的servlet。上载文件时,它会向JMS队列发送消息。接下来我写了一个监听器来检索队列中上传的消息,但是当我尝试部署它时,我收到了这个错误:
SEVERE: Invalid ejb jar [file-listener-ejb-1.0.jar]: it contains zero ejb.
Note:
1. A valid ejb jar requires at least one session, entity (1.x/2.x style), or message- driven bean.
2. EJB3+ entity beans (@Entity) are POJOs and please package them as library jar.
3. If the jar file contains valid EJBs which are annotated with EJB component level annotations (@Stateless, @Stateful, @MessageDriven, @Singleton), please check server.log to see whether the annotations were processed properly.
at com.sun.enterprise.deployment.util.EjbBundleValidator.accept(EjbBundleValidator.java:76)
...<snip>...
这是一个非常简单的项目,有一个类,使用Maven构建。该课程如下:
package my.package;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@MessageDriven(mappedName = "jms/FileUploadedQueue", activationConfig = {
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue") })
public class FileListener implements MessageListener
{
private static Logger log = LoggerFactory.getLogger(FileListener.class);
public FileListener()
{
// empty constructor
}
public void onMessage(Message message)
{
try
{
log.info("Received message: " + ((TextMessage)message).getText());
}
catch (JMSException ex)
{
String error = "Received error code '"
+ ex.getErrorCode()
+ "' retrieving message from queue jms/FileUploadedQueue.";
Exception linkedEx = ex.getLinkedException();
if (linkedEx != null)
{
log.error(error += "Linked exception: ", linkedEx);
}
else
{
log.error(error, linkedEx);
}
}
}
}
我的pom.xml看起来像这样:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my.package</groupId>
<artifactId>uploaded-file-listener</artifactId>
<version>1.0</version>
<packaging>ejb</packaging>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.4.2</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
<dependency>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
<version>1.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArguments>
<bootclasspath>${settings.localRepository}/javax/javaee-endorsed-api/6.0/javaee-endorsed-api-6.0.jar${path.separator}${sun.boot.class.path}</bootclasspath>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.3</version>
<configuration>
<ejbVersion>3.1</ejbVersion>
</configuration>
</plugin>
</plugins>
</build>
</project>
这会构建一个jar文件,当我尝试部署到我的Glassfish 3.1服务器时(通过管理控制台)会导致上述错误。
因为我的课上有@MessageDriven注释,所以我不确定我做错了什么。不幸的是,server.log文件不包含有关错误的任何更多细节。
我是否应该将罐子包装在耳朵中并进行部署?
----------的修改 ----------
我创建了一个包含ejb jar的耳朵,当我将耳朵部署到Glassfish时,我得到了同样的错误。所以,我认为它必须与注释有关。但是,我查看了多个示例/教程,我看不出有什么问题。
任何见解/建议都会受到欢迎!!
---------- 编辑两个 ----------
MANIFEST.MF文件的内容:
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: <name>
Build-Jdk: 1.6.0_24
application.xml的内容:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE application PUBLIC
"-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN"
"http://java.sun.com/dtd/application_1_3.dtd">
<application>
<display-name>FileListener-ear</display-name>
<module>
<ejb>file-listener-ejb-1.0.jar</ejb>
</module>
</application>
---------- 编辑三 ----------
ejb-jar文件的内容:
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd"
version="3.1">
<display-name>FileListener</display-name>
<enterprise-beans>
<message-driven>
<ejb-name>FileListener</ejb-name>
<ejb-class>my.package.FileListener</ejb-class>
<transaction-type>Container</transaction-type>
</message-driven>
</enterprise-beans>
</ejb-jar>