Search code examples
deploymentjardependenciesejbglassfish-4

How to deploy EJB module in Glassfish with jar dependencies


I have a maven EJB module with dependency of two SE modules, one of domain entities and other with persistence entities.

<dependencies>
    <dependency>
        <groupId>com.mycompany.modules</groupId>
        <artifactId>entities</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>com.mycompany.modules</groupId>
        <artifactId>persistent-entities</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>

I build the EJB module and when I tried to deploy ejb-module.jar in glassfish I get an error with the reference of the dependency modules:

Grave: Class [ com/mycompany/entities/EDSesion ] not found. Error while loading [ class com.mycompany.ejb.dataAccess.GestorADSesion ] Grave: Class [ com/mycompany/persistent/entities/TSesion ] not found. Error while loading [ class com.mycompany.ejb.converters.EDSesionConverter ] Grave: Cannot resolve reference Local ejb-ref name=com.mycompany.ejb.dataAccess.GestorADSesion/eDSesionFConverter,Local 3.x interface =com.mycompany.ejb.converters.interfaces.EDSesionConverterLocal,ejb-link=null,lookup=,mappedName=,jndi-name=,refType=Session Grave: Excepción al desplegar la aplicación [app-ejb-1.0] Grave: Exception during lifecycle processing java.lang.RuntimeException: Cannot resolve reference Local ejb-ref name=com.mycompany.ejb.dataAccess.GestorADAreaF/eDAreaFConverter,Local 3.x interface =com.mycompany.ejb.converters.interfaces.EDAreaFConverterLocal,ejb-link=null,lookup=,mappedName=,jndi-name=,refType=Session

Note: ED stand for Domain Entities, T stand for persistence entities, Gestor it is the class to persist entities to database and Converter is the class to convert persistence entities to domain entities. Gestor has a Local Interface

This is my build in the pom file for ejb module

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <compilerArguments>
                    <endorseddirs>${endorsed.dir}</endorseddirs>
                </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>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.6</version>
            <executions>
                <execution>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${endorsed.dir}</outputDirectory>
                        <silent>true</silent>
                        <artifactItems>
                            <artifactItem>
                                <groupId>javax</groupId>
                                <artifactId>javaee-endorsed-api</artifactId>
                                <version>7.0</version>
                                <type>jar</type>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Solution

  • Perhaps you figured out by yourself already but your EJB.jar wasn't (and never will be) packed with your dependencies.

    Therefore, you have two alternatives: build an EAR with your EJB module and your entities/persistent-entities modules or make your dependencies available directly to the container. I prefer the first approach.