通常我会去java.net网站查看我得到的错误代码是什么,但他们的网站目前处于脱机状态.基本上我遵循这个指南:
http://pookey.co.uk/wordpress/archives/95-getting-started-with-glassfish-using-maven
尝试获取部署在我的GlassFish应用程序服务器上的示例maven Web应用程序.我的POM文件如下:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.cellnet.test</groupId>
<artifactId>hello-world</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>hello-world Maven Webapp</name>
<url>http://maven.apache.org</url>
<pluginRepositories>
<pluginRepository>
<id>maven.java.net</id>
<name>Java.net Maven2 Repository</name>
<url>http://download.java.net/maven/2</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>hello-world</finalName>
<plugins>
<plugin>
<groupId>org.glassfish.maven.plugin</groupId>
<artifactId>maven-glassfish-plugin</artifactId>
<version>2.1</version>
<configuration>
<user>admin</user>
<adminPassword>password</adminPassword>
<glassfishDirectory>C:\glassfish3</glassfishDirectory>
<components>
<component>
<name>${project.artifactId}</name>
<artifact>${project.build.directory}/${project.build.finalName}.war</artifact>
</component>
</components>
<domain>
<name>domain1</name>
<adminPort>4848</adminPort>
<httpPort>8080</httpPort>
<httpsPort>8443</httpsPort>
</domain>
</configuration>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
我的GlassFish应用程序服务器已启动并运行,但执行时出现以下错误消息
mvn war:war glassfish:deploy
Failed to execute goal org.glassfish.maven.plugin:maven-glassfish-plugin:2.1:
deploy (default-cli) on project hello-world: Deployment of myPathToMavenProject.war …
Run Code Online (Sandbox Code Playgroud) 我试图使用嵌入式EJB容器测试我的EJB.在生产中,我依赖于在应用程序服务器中配置的JTA数据源.但是,在测试期间,我想连接到不同的DB(内存中的Derby).
问题是我无法看到如何告诉EJB容器覆盖生产persistence.xml中定义的JTA数据源(在src/main/resources/META-INF中),并连接到我的内存中的derby DB.JTA数据源在persistence.xml文件中定义,如下所示:
<jta-data-source>jdbc/myDS</jta-data-source>
Run Code Online (Sandbox Code Playgroud)
我尝试创建一个测试persistence.xml文件(在src/test/resources/META-INF中),该文件定义:
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:derby:memory:myDataBase;create=true;" />
<property name="javax.persistence.jdbc.user" value="sa" />
<property name="javax.persistence.jdbc.password" value="password" />
Run Code Online (Sandbox Code Playgroud)
但这是没有意义的,因为当我指定EJB容器使用被测模块时
Map properties = new HashMap();
properties.put(EJBContainer.MODULES, new File[] { new File("target/classes/") });
ec = EJBContainer.createEJBContainer(properties);
Run Code Online (Sandbox Code Playgroud)
容器只使用主persistence.xml文件而不是我的测试文件.
我能看到使这种方法有效的唯一方法是使用这里描述的方法- 将被测模块的类复制到一个单独的位置(例如target/ejb-testing-classes),然后复制测试persistence.xml将文件放在顶部,然后将此新位置指定给EJB容器:
Map properties = new HashMap();
properties.put(EJBContainer.MODULES, new File[] { new File("target/ejb-testing-classes/") });
ec = EJBContainer.createEJBContainer(properties);
Run Code Online (Sandbox Code Playgroud)
但这似乎是不必要的笨拙.如果我试图在容器中部署预先打包的模块(即依赖项),那么将来也可能是一个问题,因为我需要在合并之前爆炸jar.
我认为可能有其他属性可以传递到EJB容器中,但到目前为止我只能找到适合openEJB或websphere的属性.我使用嵌入式Glassfish来提供我的嵌入式EJB容器,因为它是目标平台.(我现在已经找到了glassfish属性 - 请参阅下面的更新#1)
当然,每个尝试使用嵌入式EJB容器和不同于生产数据库的数据源测试EJB的人都会遇到这个问题.即便是这个人也放弃了这一点并使用了默认的嵌入式数据库,这对我来说不是一个选择.
任何帮助将非常感激.
更新1:我找到了Glassfish EJB容器接受的属性列表,起初看起来我可以使用以下属性
org.glassfish.ejb.embedded.glassfish.configuration.file
Run Code Online (Sandbox Code Playgroud)
在domain.xml中定义数据源并将容器指向它.但是,根据 …
我需要将我的JavaEE应用程序作为目录部署在Glassfish上,而不是打包的WAR文件.是否可以使用Maven Glassfish插件将目录部署到Glassfish?
使用管理控制台,它是可能的.但我希望能够在命令行上执行此操作.
我刚开始使用maven-glassfish-plugin.我开始了域名目标.但是,当我尝试执行部署目标时,插件认为域未启动并尝试重新启动它 - 这显然会失败.见下面的日志:
> mvn glassfish:start-domain
[INFO] --- maven-glassfish-plugin:2.1:start-domain (default-cli) @ arquillian-sample ---
[INFO] Deprecated syntax, instead use:
[INFO] asadmin --passwordfile C:\apps\glassfish-3.0.1\glassfish/domains/domain1/config/domain-passwords --interactive=false --user admin --echo --terse=false start-domain [options] ...
[INFO] asadmin --host localhost --port 4848 --user admin --passwordfile C:\apps\glassfish-3.0.1\glassfish/domains/domain1/config/domain-passwords --interactive=false --echo=true --terse=false start-domain --debug=true --domaindir C:\apps\glassfish-3.0.1\glassfish\domains --help=false --upgrade=false --verbose=false domain1
[INFO] Waiting for DAS to start ...
[INFO] Started domain: domain1
[INFO] Domain location: C:\apps\glassfish-3.0.1\glassfish\domains\domain1
[INFO] Log file: C:\apps\glassfish-3.0.1\glassfish\domains\domain1\logs\server.log
[INFO] Admin port for the domain: 4848
[INFO] Debug port …
Run Code Online (Sandbox Code Playgroud)