Glassfish嵌入式无法部署EJB模块

时间:2015-10-18 17:39:37

标签: java maven junit glassfish

有人可以帮我解决JUnit4.12和glassfish4.1的错误吗?

我试图使用JUnit测试EJB,但是我从JUnit跟踪中得到了这条消息:

javax.ejb.EJBException: Failed to deploy EJB modules - see log for details
at org.glassfish.ejb.embedded.EJBContainerImpl.deploy(EJBContainerImpl.java:149)

使用maven我的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>com.leorm.sga</groupId>
<artifactId>sga-jee-last</artifactId>
<version>1.0</version>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <glassfish.embedded-static-shell.jar>
        /opt/servers/glassfish4/glassfish/lib/embedded/glassfish-embedded-static-shell.jar
    </glassfish.embedded-static-shell.jar>
</properties>
<dependencies>
    <dependency>
        <groupId>org.glassfish.main.extras</groupId>
        <artifactId>glassfish-embedded-static-shell</artifactId>
        <version>4.1</version>
        <scope>system</scope>
        <systemPath>${glassfish.embedded-static-shell.jar}</systemPath>
    </dependency>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>7.0</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
    </dependency>
</dependencies>

我的JUnit测试用例是:

...
public class PersonaServiceTest {

private PersonaService personaService;

@Before
public void setUp() throws NamingException{
    EJBContainer contenedor = EJBContainer.createEJBContainer();
    personaService = (PersonaService) contenedor.getContext().lookup("ejb/Persona");

}

@Test
public void test() {
    System.out.println("Starting test EJB PersonaService");
    assertTrue(personaService != null);

    assertEquals(2, personaService.listarPersonas().size());

    System.out.println("Count personas is:" + personaService.listarPersonas().size());

    this.desplegarPersonas(personaService.listarPersonas());
    System.out.println("End test EJB PersonaService");
}

private void desplegarPersonas(List<Persona> personas) {
    for(Persona persona: personas){
        System.out.println(persona);
    }

}

}

控制台说:

INFO: [EJBContainerImpl] GlassFish status: STARTED
Oct 18, 2015 11:33:56 AM org.glassfish.ejb.embedded.EJBContainerImpl deploy
INFO: [EJBContainerImpl] Deploying as a ScatteredArchive
Oct 18, 2015 11:33:57 AM    org.glassfish.deployment.common.GenericAnnotationDetector scanArchive
WARNING: NCLS-DEPLOYMENT-00009
Oct 18, 2015 11:33:57 AM org.glassfish.api.ActionReport failure
SEVERE: Archive type of /tmp/classes.jar was not recognized
Oct 18, 2015 11:33:57 AM org.glassfish.ejb.embedded.EJBContainerProviderImpl createEJBContainer
INFO: [EJBContainerProviderImpl] Cleaning up on failure ...
JdbcRuntimeExtension,  getAllSystemRAResourcesAndPools = [GlassFishConfigBean.org.glassfish.jdbc.config.JdbcResource, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcResource, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcConnectionPool, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcConnectionPool]
Oct 18, 2015 11:33:57 AM org.glassfish.admin.mbeanserver.JMXStartupService shutdown
INFO: JMXStartupService and JMXConnectors have been shut down.
Oct 18, 2015 11:33:57 AM org.glassfish.admin.mbeanserver.JMXStartupService shutdown
INFO: JMXStartupService and JMXConnectors have been shut down.
JdbcRuntimeExtension,  getAllSystemRAResourcesAndPools = [GlassFishConfigBean.org.glassfish.jdbc.config.JdbcResource, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcResource, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcConnectionPool, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcConnectionPool]
Oct 18, 2015 11:33:57 AM com.sun.enterprise.v3.server.AppServerStartup stop
INFO: Shutdown procedure finished

1 个答案:

答案 0 :(得分:2)

我在eclipse中作为独立的JUnit(不是通过maven测试)运行此类测试的个人经验是使用createEJBContainer的重载版本,其中开发人员必须指定在何处查找已编译的bean类。假设EJB类位于{currentProject} / target / classes并使用EJB注释,以下解决了同样的问题:

NoneType