有人知道嵌入式 Glassfish 吗?我想运行一些 EJB 测试,但我不想在每次运行测试时启动和停止 glassfish-embedded。
根据插件文档,我应该把它放在 POM 中:
<plugin>
<groupId>org.glassfish</groupId>
<artifactId>maven-embedded-glassfish-plugin</artifactId>
<version>3.1</version>
<configuration>
<app>target/ejbcontainer-1.0-SNAPSHOT.jar</app>
<name>test</name>
<ports>
<http-listener>8080</http-listener>
<https-listener>8181</https-listener>
</ports>
</configuration>
<executions>
<execution>
<goals>
<goal>start</goal>
<goal>deploy</goal>
<goal>undeploy</goal>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
</configuration>
</execution>
</executions>
</plugin>
这一切都很好。我可以“运行”这个嵌入式 glassfish,并在我的控制台中得到它,这证明它已经启动并正在运行:
信息:测试在 1,124 毫秒内成功部署。PlainTextActionReporterSUCCESSDescription:部署 AdminCommandApplication 部署名称测试。[name=test 2013 年 12 月 16 日 6:03:29 PM PluginUtil doDeploy 信息:已部署测试按 ENTER 重新部署,X 退出
但是,当我“运行”我的测试文件时,会创建一个嵌入式 glassfish的新实例。
我的测试文件没有选择当前正在运行的容器。
如果有帮助,这是一个测试文件:
public class Test extends TestCase {
private Context ctx;
private EJBContainer ejbContainer;
public Test(String testName) {
super(testName);
}
@BeforeClass
public void setUp() {
ejbContainer = EJBContainer.createEJBContainer();
System.out.println("Opening the container");
ctx = ejbContainer.getContext();
}
@AfterClass
@Override
public void tearDown() {
ejbContainer.close();
System.out.println("Closing the container");
}
@org.junit.Test
public void testApp() throws Exception {
TemperatureConverter converter = (TemperatureConverter) ctx.lookup("java:global/classes/TemperatureConverter");
assertNotNull(converter);
}
}