开发者

Exception Deploying EJB Jar to Glassfish

开发者 https://www.devze.com 2023-03-28 18:53 出处:网络
This is my first foray into using JMS.I have a successfully created/deployed a war file that contains a servlet that I can use to upload files.When a file is开发者_如何学运维 uploaded it sends a messa

This is my first foray into using JMS. I have a successfully created/deployed a war file that contains a servlet that I can use to upload files. When a file is开发者_如何学运维 uploaded it sends a message to a JMS queue. Next I wrote a listener to retrieve the uploaded messages from the queue, but when I try to deploy it, I get this error:

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>...

It's a very simple project with one class, built using Maven. The class looks like this:

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);
            }
        }
    }
}

My pom.xml looks like this:

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

This builds a jar file which when I try to deploy to my Glassfish 3.1 server (via the admin console) results in the above error.

Since I have the @MessageDriven annotation on my class, I'm not sure what I'm doing wrong. Unfortunately, the server.log file does not contain any more details about the error.

Should I be packaging the jar in an ear and deploying that?

----------EDIT----------

I created an ear which includes the ejb jar, and I get the same error when I deploy the ear to Glassfish. So, I think it must be something to do with the annotation. However, I've looked at multiple examples/tutorials and I can't see what's wrong.

Any insights/suggestions would be most welcome!!

----------EDIT TWO----------

Contents of MANIFEST.MF files:

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: <name>
Build-Jdk: 1.6.0_24

Contents of 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>

----------EDIT THREE----------

Contents of ejb-jar file:

<?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>


Does your jar file contain an ejb-jar.xml file? If it was missing, then it could explain why the whole thing explodes upon deploy


Deploying on GF 4.1 our EAR that consists of an EJB and WAR and several JAR projects suddenly needs an application.xml.

Many deploys before it was not necessary.


Exception Deploying EJB Jar to Glassfish

Did you try to check the compatibility check box while deployment and see if deploys fine. We also got such error preventing the deployment and was resolved by checking the compatibility check box while deployment.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号