【发布时间】:2015-07-09 07:34:05
【问题描述】:
我有两个 Maven 模块。一个名为tests,一个名为ws-ejb。
在 tests pom.xml 中,我已将 ws-ejb 设置为依赖项,因此我可以在测试中使用 EJB。
这是我的tests maven 模块的 pom.xml 的缩短版本:
<parent>
<artifactId>myproj</artifactId>
<groupId>myproj</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>tests</artifactId>
<dependencies>
<dependency>
<groupId>myproj</groupId>
<artifactId>ws-ejb</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>test</scope>
<type>war</type>
<dependencies>
<dependency>
...
<!-- other dependencies in the file: junit and javax.ejb -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>tests</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
<plugin>
<plugins>
<build>
但是当我运行我的测试时,我得到一个编译错误,指出我的 bean 无法找到,但我将它作为依赖项,我的 IDE 没有抱怨丢失的 bean,但 maven 会:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:testCompile (default-testCompile) on project tests: Compilation failure: Compilation failure:
[ERROR] /home/r/projects/myproj/trunk/tests/src/test/java/com/myproj/MyTest.java [3,19]package com.myproj.beans does not exist
包com.myproj.beans 确实存在于我在tests 模块中设置为依赖项的maven 模块ws-ejb 中。那么有什么问题呢?
编辑
这是位于tests maven 模块中src/test/java/com/myproj/MyTest.java 下的MyTest.java
package com.myproj;
import com.myproj.beans.MyBean; // compilation error here. If I remove this line it works and the test is run!
//MyBean is located at `ws-ejb` maven module under src/main/java/com.myproj.beans
import javax.ejb.EJB;
import org.junit.Test;
public class MyTest {
@Test
public void test() {System.out.println("Print something...");}
}
【问题讨论】:
-
所以
com.myproj.beans来自那个战争?为什么一定是战争?不能是 JAR 吗? -
好吧,
ws-ejb是一个 WAR,所以我应该将它指定为一个 WAR。
标签: java maven maven-compiler-plugin maven-module