我有一个现有的JEE Maven和Eclipse项目:
mainProject.ear
+--project1.war
+--project2.war
+--ejb-proj.jar
我想有一个测试配置文件,用于测试EJB项目,包括使用JPA读/写数据库。
我在pom.xml
添加了一个依赖项,如下所示:
<!-- Embedded glassfish -->
<plugin>
<groupId>org.glassfish</groupId>
<artifactId>maven-embedded-glassfish-plugin</artifactId>
<version>3.0-74b</version>
<configuration>
<goalPrefix>embedded-glassfish</goalPrefix>
<port>8080</port>
<autoDelete>true</autoDelete>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.44</version>
</dependency>
</dependencies>
然后我创建了一个测试类:
@Before
public void setup() {
// instantiate container and context
ejbContainer = EJBContainer.createEJBContainer();
logger.info("Opening the container");
ctx = ejbContainer.getContext();
}
这些是Maven的目标,在Eclipse&#34;跳过测试&#34;是没有标志的:
clean compile package
Glassfish已正确启动但我收到有关缺少jdbc驱动程序的错误。
Class name is wrong or classpath is not set for : com.mysql.jdbc.jdbc2.optional.MysqlDataSource
所以,这些是问题:
为了完整性,与skip test = true
相同的maven目标才有效。部署在正在运行的容器中的.ear也可以工作。