Maven错误:在包中找不到符号类

德曼

这是我第一次使用Maven,我正在尝试了解它的工作原理。因此,我有一个小例子,在不同的包中有两个类。

package maven.callee ;

public class Callee {
  public void callMe() {
   System.out.println("Callee says: You called me!");
  }
}

现在具有主要功能的Caller类。

package maven.caller ;
import maven.callee.Callee ;

public class Caller {
  public static void main(String [] args) {
   Callee callee = new Callee ();
   callee.callMe ();
  }
}

我知道src目录的结构与标准不同。当我在pom.xml文件上运行命令mvn包时,得到以下输出:

[INFO] Compiling 1 source file to /home/ced/workspaceForOxygene/build/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /home/ced/workspaceForOxygene/build/src/maven/caller/Caller.java:[2,20] package maven.callee does not exist
[ERROR] /home/ced/workspaceForOxygene/build/src/maven/caller/Caller.java:[6,4] cannot find symbol
  symbol:   class Callee
  location: class maven.caller.Caller
[ERROR] /home/ced/workspaceForOxygene/build/src/maven/caller/Caller.java:[6,24] cannot find symbol
  symbol:   class Callee
  location: class maven.caller.Caller
[INFO] 3 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.645 s
[INFO] Finished at: 2018-04-24T17:12:36+02:00
[INFO] Final Memory: 13M/158M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.2:compile (default-compile) on project mavenTest: Compilation failure: Compilation failure:
[ERROR] /home/ced/workspaceForOxygene/build/src/maven/caller/Caller.java:[2,20] package maven.callee does not exist
[ERROR] /home/ced/workspaceForOxygene/build/src/maven/caller/Caller.java:[6,4] cannot find symbol
[ERROR] symbol:   class Callee
[ERROR] location: class maven.caller.Caller
[ERROR] /home/ced/workspaceForOxygene/build/src/maven/caller/Caller.java:[6,24] cannot find symbol
[ERROR] symbol:   class Callee
[ERROR] location: class maven.caller.Caller
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

请问发生了什么事?为什么Maven无法找到该文件?hier是我的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/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.swt.build</groupId>
    <artifactId>mavenTest</artifactId>
    <version>1.0</version>

    <build>
        <sourceDirectory>src/maven/caller</sourceDirectory>
        <!--specify output directory for binaries -->
        <outputDirectory> classes </outputDirectory>

           <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins </groupId>
                <artifactId> maven-jar-plugin</artifactId>
                <version> 3.0.2</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath> true </addClasspath>
                            <mainClass> maven.caller.Caller </mainClass>                        
                        </manifest>
                    </archive> 
                    <!--specify output directory for jar file -->
                    <outputDirectory>jars</outputDirectory>   
                </configuration>
            </plugin>
        </plugins>

      </build>      
</project>  
维诺德

编译器路径中缺少maven.callee。它应该是源目录的一部分,或者应该定义为lib依赖项。使用当前设置,Maven将尝试仅在src / maven / caller下编译Java文件。在pom.xml中将sourceDirectory更改为src / maven。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章