2

我创建了一个新项目,它只会运行集成测试

  • maven-ear-插件
  • maven-failsafe-插件
  • maven 嵌入式 glassfish 插件

当我将包装设置为 ear 时,ear 文件被创建,glassfish 运行但测试被忽略,我收到以下消息

[failsafe:integration-test] 没有要运行的测试。

并且 glassfish 取消部署失败

[嵌入式玻璃鱼:取消部署]
2012 年 8 月 17 日上午 10:08:17 PluginUtil doUndeploy
信息:部署者 = com.sun.enterprise.admin.cli.embeddable.DeployerImpl@105f0f87 2012 年
8 月 17 日上午 10:08:17 com.sun.enterprise.loader.ASURLClassLoader$SentinelInputStream
报告
警告:输入流已被最终确定或强制关闭,但未明确
关闭; 在 com.sun.enterprise.loader.ASURLClassLoader$SentinelInputStream的以下堆栈跟踪
java.lang.Throwable 中报告了流实例化。(ASURLClassLoader.java:1230)

当我将包装设置为罐子时,我得到

运行 packageName.MyServiceTest
17/08/2012 10:09:34 AM com.sun.enterprise.v3.server.CommonClassLoaderServiceImpl
findDerbyClient 信息:找不到 javadb 客户端 jar 文件,derby jdbc 驱动程序默认
不可用。org.omg.CORBA.COMM_FAILURE:FINE:IOP00410001:连接失败:socketType:IIOP_CLEAR_TEXT;主机名:本地主机;端口:3700 vmcid:OMG 次要代码:1 已完成: 在 sun.reflect.GeneratedConstructorAccessor27.newInstance 处没有(未知来源)




并且 glassfish 没有启动

我知道它与 Maven 生命周期有关,它不允许我创建 ear 文件、启动 glassfish 嵌入式服务器并在同一个项目中运行集成测试。

有人可以建议我一个解决方案吗?我正在尝试仅使用 EJB 和业务实体项目创建 ear 文件并将其部署到嵌入式 glassfish 服务器以使用 maven-failsafe-plugin 运行集成测试,而不是部署由父 pom.xml 创建的 ear 文件,它添加UI等项目放入ear文件。

这是我的 pom.xml 文件

http://maven.apache.org/xsd/maven-4.0.0.xsd">4.0.0

<parent>
    <groupId>company.MyProject</groupId>
    <artifactId>MyProject</artifactId>
    <version>3.8.1-SNAPSHOT</version>
</parent>

<artifactId>MyProject-integration-test</artifactId>
<packaging>jar</packaging>

<name>MyProject Integration Tests</name>

<properties>
    <ear-final-name>MyProject-integration-test-${project.version}</ear-final-name>
</properties>

<dependencies>
    <dependency>
        <groupId>org.glassfish.extras</groupId>
        <artifactId>glassfish-embedded-all</artifactId>
        <version>3.1.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.concordion</groupId>
        <artifactId>concordion</artifactId>
        <version>1.4.2</version>
        <scope>test</scope>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>org.concordion</groupId>
        <artifactId>concordion-extensions</artifactId>
        <version>1.0.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>MyProject-ejb</artifactId>
        <version>${project.version}</version>
        <type>ejb</type>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-words-jdk15</artifactId>
        <version>${aspose.libraryVersion}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>javax.persistence</groupId>
        <artifactId>persistence-api</artifactId>
        <version>1.0.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>hibernate-entitymanager</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>3.4.0.GA</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>3.3.2.GA</version>
    </dependency>
    <dependency>
        <groupId>hibernate-annotations</groupId>
        <artifactId>hibernate-annotations</artifactId>
        <version>3.4.0.GA</version>
    </dependency>
    <dependency>
        <groupId>hibernate-commons-annotations</groupId>
        <artifactId>hibernate-commons-annotations</artifactId>
        <version>3.4.0.GA</version>
    </dependency>
    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc14</artifactId>
        <version>10.1.0.5.0</version>
    </dependency>
    <dependency>
        <groupId>ehcache</groupId>
        <artifactId>ehcache</artifactId>
        <version>1.2.3</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.6.6</version>
    </dependency>
    <dependency>
        <groupId>org-apache-commons-logging</groupId>
        <artifactId>org-apache-commons-logging</artifactId>
        <version>1.1.0</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-ear-plugin</artifactId>
            <version>2.5</version>
            <configuration>
                <version>5</version>
                <displayName>MyProject</displayName>
                <defaultLibBundleDir>lib</defaultLibBundleDir>
                <finalName>${ear-final-name}</finalName>
                <name>MyProject-integration-test</name>
                <modules>
                    <ejbModule>
                        <groupId>company.MyProject</groupId>
                        <artifactId>MyProject-ejb</artifactId>
                        <bundleFileName>MyProject-ejb.jar</bundleFileName>
                    </ejbModule>
                    <jarModule>
                        <groupId>company.MyProject</groupId>
                        <artifactId>MyProject-business-entities</artifactId>
                        <bundleFileName>MyProject-business-entities-3.8.1-SNAPSHOT.jar</bundleFileName>
                    </jarModule>
                    <jarModule>
                        <groupId>company.MyProject</groupId>
                        <artifactId>MyProject-util</artifactId>
                        <bundleFileName>MyProject-util-3.8.1-SNAPSHOT.jar</bundleFileName>
                    </jarModule>
                </modules>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.12</version>
            <executions>
                <execution>
                    <id>failsafe-integration-tests</id>
                    <phase>integration-test</phase>
                    <goals>
                        <goal>integration-test</goal>
                    </goals>
                </execution>
                <execution>
                    <id>failsafe-verify</id>
                    <phase>verify</phase>
                    <goals>
                        <goal>verify</goal>
                    </goals>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                    <version>4.8.2</version>
                </dependency>
            </dependencies>
        </plugin>

        <plugin>
            <groupId>org.glassfish</groupId>
            <artifactId>maven-embedded-glassfish-plugin</artifactId>
            <version>3.1.1</version>
            <configuration>
                <goalPrefix>embedded-glassfish</goalPrefix>
                <autoDelete>true</autoDelete>
                <app>${basedir}/target/MyProject-integration-test-${project.version}.ear</app> 
                <port>8080</port>
                <configFile>src/test/resources/glassfish/config/domain.xml</configFile>
            </configuration>
            <executions> 
                <execution>
                    <id>start-glassfish</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>start</goal>
                    </goals>
                </execution>
                <execution>
                    <id>glassfish-deploy</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>deploy</goal>
                    </goals>
                </execution>
                <execution>
                    <id>glassfish-undeploy</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>undeploy</goal>
                    </goals>
                </execution>

                <execution>
                    <id>stop-glassfish</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>stop</goal>
                    </goals>
                </execution>
            </executions> 
        </plugin> 
    </plugins>

</build>

4

3 回答 3

1

是的,它现在工作。原来问题出在我的 domain.xml 文件上。默认 domain.xml 带有前缀为 2 的端口号,应将其删除,并且在嵌入式 glassfish 3.1 <port> 8080 < /port> 中如果设置了 <configFile> 则不起作用(参考此文档) http://embedded- glassfish.java.net/nonav/plugindocs/3.1/stop-mojo.html

我只需将 domain.xml 中的 IIOP 端口设置为 3700 并在我的测试中

 Properties props = new Properties();  
 props.put("org.omg.CORBA.ORBInitialPort", "3700");
 Context ctx = new InitialContext(props);   

多谢你们

于 2012-08-22T12:32:09.157 回答
0

您可以在一次调用中完成打包和启动 glassfish。

你有没有尝试过:

mvn verify 

这样做?

于 2012-08-17T07:14:34.737 回答
0

可能是另一种指定 Glassfish 的 IIOP 端口的解决方案(首先需要确认服务器 IP 和 IIOP 侦听器端口):

System.setProperty("org.omg.CORBA.ORBInitialHost", "127.0.0.1");
System.setProperty("org.omg.CORBA.ORBInitialPort", "8037");
Context ctx = new InitialContext();
于 2017-11-23T23:31:55.633 回答