ven 2和NetBeans IDE 6.0构建EJB 3(9)
时间:2011-02-07 Jacek Laskowski
模块配置的一个有趣的部分是 maven-surefire-plugin的配置,默认情况下它只执行符合 none模式的测试,以这种方式进行配置(在本例中 none模式意味着不会执行任何测试,因为所有测试都不符合模式,但是执行单个的 RemovableClientTest会更加准确),并且只在完成集成测试阶段期间执行。
不管客户机类的可访问性如何,我们将从m2级别执行自动启动,此过程需要借助一个测试——RemovableClientTest( pl.jaceklaskowski.javaee.RemovableClientTest 类别),该测试是通过 Test Packages文件夹构建的。
package pl.jaceklaskowski.javaee;
import javax.naming.Context;
import javax.naming.InitialContext;
import org.junit.Test;
public class RemovableClientTest {
@Test
public void runRemoteClient() throws Exception {
Context ctx = new InitialContext();
RemovableRemote removable = (RemovableRemote) ctx.lookup("Removable");
removable.remove("Look at the server''s log");
}
}
这种类型的测试在默认情况下不会启动(请参考pom.xml文件中的maven-surefire-plugin配置),因为在启动测试之前,需要在GlassFish应用服务器上先启动bean(如果修改了测试实现方式,则不能够创建项目并且也不能在服务器上安装bean)。
启动
要启动项目,首先要在GlassFish服务器上安装 Removable bean ,然后启动 RemovableClientTest。
GlassFish服务器启动
在安装bean之前,我们先要使用asadmin start-domain命令启动GlassFish(之前已定义了变量PATH以包含GlassFish bin 目录)。
$ asadmin.bat start-domain domain1
Starting Domain domain1, please wait.
Log redirected to c:appsglassfishdomainsdomain1logsserver.log.
Redirecting output to C:/apps/glassfish/domains/domain1/logs/server.log
Domain domain1 is ready to receive client requests. Additional services are being started in
background.
Domain [domain1] is running [Sun Java System Application Server 9.1 (build b58d-fcs)]
with its configuration and logs at: [c:appsglassfishdomains].
Admin Console is available at [http://localhost:4848].
Use the same port [4848] for "asadmin" commands.
User web applications are available at these URLs:
[http://localhost:8080 https://localhost:8181 ].
Following web-contexts are available:
[/web1 /__wstx-services ].
Standard JMX Clients (like JConsole) can connect to JMXServiceURL:
[service:jmx:rmi:///jndi/rmi://dev:8686/jmxrmi] for domain management purposes.
Domain listens on at least following ports for connections:
[8080 8181 4848 3700 3820 3920 8686 ].
Domain does not support application server clusters and other standalone instances.
安装EJB bean——Removable
在创建之前,先要安装bean 。然而,在定义客户机依赖关系( ejb3-remove-stateless-client 项目)的过程中实际已经完成了这一步骤。在 ejb3-remove-stateless-ejb3项目target 目录,存在一个ejb3-remove-stateless-ejb3-1.0.jar文件。这是一个bean分配文件。我们将使用asadmin deploy 命令安装该文件。
$ asadmin.bat deploy --user admin
ejb3-remove-stateless-ejb3/target/ejb3-remove-stateless-ejb3-1.0.jar
Command deploy executed successfully.
使用GlassFish v2、Apache Maven 2和 |