1

For a webapp project, I am using Eclipse + Jax-RS Jersey 2.5 + JPA 2.0, and I am facing some weird problems after deploying the application on Glassfish server from Eclipse.

In fact, everything works fine if I hit "Run on server", let the deployment end and then restart the Glassfish server ; btw, it's not very effective when developing, 'cause it leads to a lot a wasted time...

If I just hit "Run on server", then none of my EJB's are being injected, resulting in NullPointerException that prevent me from doing anything.

I used Maven for dependencies management, could it come from it ? Should I use another way than "Run on server" to redeploy my application after code change ?

Thanks

EDIT : Here is the architecture of the project :

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

EDIT 2 :

Even with this script it does not work :

/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 are injected with EJB annotation, and specifying the LOOKUP name :

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

Class :

@Stateless
public class CustomApplicationService {

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

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

Finally, my 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>
Zword
  • 6,605
  • 3
  • 27
  • 52
Jérémy Dutheil
  • 6,099
  • 7
  • 37
  • 52
  • That's exactly it ; structure is based on a simple .war project generated by Maven. I edited my first post – Jérémy Dutheil Feb 05 '14 at 09:40
  • In fact, I already tryied undeploying manually and nothing changed ; I also tryied to use a specific script without success, see my edit ;) – Jérémy Dutheil Feb 05 '14 at 15:20
  • OK, at least one is clear: it is not a problem from Eclipse. Have you tried upgrading the Glassfish server (if possible)? I cleared up my comments for readability. – V G Feb 05 '14 at 15:24
  • Yep, glassfish version is nightly build ; I even updated Jersey version to 2.5.1 – Jérémy Dutheil Feb 05 '14 at 16:04
  • Try removing the `name` property from the `@EJB` annotation, as the EJB container should figure out alone that. I have never used additional properties there, but it seems that you put the JNDI name in the name property. As I see you do not get the EJB injected in other EJBs, NOT in the rest resources. – V G Feb 06 '14 at 09:21
  • Nop, EJB are injected inside resource ; I have put the name to try to solve this problem by looking into JNDI, doesn't change anything without it :/ – Jérémy Dutheil Feb 07 '14 at 15:03
  • As far as I know, that annotation is accepted only inside other EJBs. Are your rest resources annotated with @EJB? – V G Feb 07 '14 at 15:14

0 Answers0