Glassfish上的Jersey + JPA部署无法重启而无法正常工作

时间:2014-01-28 14:07:09

标签: eclipse jpa glassfish jersey glassfish-4

对于一个webapp项目,我使用Eclipse + Jax-RS Jersey 2.5 + JPA 2.0,在Eclipse上从Glassfish服务器上部署应用程序后,我遇到了一些奇怪的问题。

事实上,如果我点击“Run on server”,一切正常,让部署结束,然后重新启动Glassfish服务器;顺便说一句,它在开发时效果不是很好,因为它会浪费很多时间......

如果我只是点击“Run on server”,那么我的EJB都没有注入,导致NullPointerException阻止我做任何事情。

我使用Maven进行依赖管理,它可以来自它吗?我应该使用“运行在服务器上”之外的其他方式在代码更改后重新部署我的应用程序吗?

由于

编辑:这是该项目的架构:

src/
    main/
        java/
            /* Application packages */
        resources/
            META-INF/
                persistence.xml
        webapp/
            WEB(INF/
                beans.xml
            /* App templates */
pom.xml

编辑2:

即使使用此脚本也不起作用:

/opt/apache-maven-3.1.1/bin/mvn clean package
/opt/glassfish4/glassfish/bin/asadmin --host localhost --port 4848 --user admin --passwordfile /opt/glassfish4/glassfish/domains/domain1/config/admin-keyfile --interactive=false --echo=true --terse=false undeploy --keepreposdir=true --isredeploy=false --cascade=false --_ignorecascade=false --_classicstyle=false configurator
/opt/glassfish4/glassfish/bin/asadmin --host localhost --port 4848 --user admin --passwordfile /opt/glassfish4/glassfish/domains/domain1/config/admin-keyfile --interactive=false --echo=true --terse=false deploy --name configurator --force=false --precompilejsp=false --verify=false --generatermistubs=false --availabilityenabled=false --asyncreplication=true --keepreposdir=true --keepfailedstubs=false --isredeploy=false --logreportederrors=true --_classicstyle=false --upload=false /home/jeremy/workspace-configurator-v2/trunk/configurator/target/configurator.war

EJB注入了EJB注释,并指定了LOOKUP名称:

@EJB( name=CustomApplicationService.LOOKUP_NAME )
private CustomApplicationService customApplicationService;

班级:

@Stateless
public class CustomApplicationService {

public final static String LOOKUP_NAME = "java:global/configurator/CustomApplicationService";

    @PersistenceContext( name=UtilConsts.DATABASE_POOL )
    private EntityManager em;
       /**** */
}

最后,我的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/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>com.virtualsensitive</groupId>
    <artifactId>configurator</artifactId>
    <packaging>war</packaging>
    <version>2</version>
    <name>configurator</name>

    <dependencies>
        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>javax.ws.rs-api</artifactId>
            <version>2.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet</artifactId>
            <version>2.5.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-json-jackson</artifactId>
            <version>2.5.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-multipart</artifactId>
            <version>2.5.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>javax.persistence</artifactId>
            <version>2.1.0</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish</groupId>
            <artifactId>javax.ejb</artifactId>
            <version>3.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish</groupId>
            <artifactId>javax.servlet</artifactId>
            <version>3.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.jdom</groupId>
            <artifactId>jdom2</artifactId>
            <version>2.0.5</version>
        </dependency>
    </dependencies>

    <build>
        <finalName>configurator</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <inherited>true</inherited>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <properties>
        <jersey.version>2.5.1</jersey.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
</project>

0 个答案:

没有答案