我的 maven 模块在我的其他 maven 模块中找不到 class 尽管我将它设置为依赖项

My maven module cannot find class in my other maven module though I am setting it as dependency

我有两个 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 中。那怎么了?

编辑

这是 MyTest.java 位于 src/test/java/com/myproj/MyTest.java

下的 tests maven 模块中
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...");}
}

由于您没有 post 任何示例代码,我只能猜测。但我的猜测是您的测试代码不在您项目的测试文件夹中。那么这是什么意思?这意味着 Maven 只是试图编译 and/or 运行 你的测试项目,这会导致异常。尝试从您的依赖项中删除 scope 属性,然后再试一次。仅当您将测试文件夹与例如 JUnit 一起使用时,测试范围才会起作用。如果您的代码位于 "main" 文件夹中,这将不起作用,因为在 运行 时间无法访问依赖项。如果有什么不清楚或者你有一些我没有得到的信息,请评论:)
亲切的问候
编辑:对此进行一些扩展:我强烈建议在工件中为给定工件编写测试代码作为测试。这样,如果测试失败,您将在有错误的工件中遇到 maven 构建失败。要查看这是如何工作的,您只需为特定的 class 添加 JUnit 测试(大多数 IDE 都会支持您)
编辑 2:好的,我做了一个快速的谷歌搜索:this article 可以提供关于如何使用 classes 的答案。我希望这能解决问题:)