【发布时间】:2015-05-02 10:01:14
【问题描述】:
我正在开发一个“复杂”/“结构良好”的 Maven 项目,特别是我正在开发该项目的单个内部模块。我反对编译错误,因为它似乎没有从已经从菜单链接的外部源中找到 Java 类(右键单击项目)-> 构建路径-> 链接源。 这是我运行时从控制台获取的一堆基本错误-> mvn:编译
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project optimizer: Compilation failure: Compilation failure:
[ERROR] /Users/Ste/Desktop/eclip/workspace/planner/src/main/java/eu/planner/Module.java:[24,19] package jmetal.core does not exist
[ERROR] /Users/Ste/Desktop/eclip/workspace/planner/src/main/java/eu/planner/Module.java:[35,29] cannot find symbol
[ERROR] symbol: class Variable
[ERROR] /Users/Ste/Desktop/eclip/workspace/planner/src/main/java/eu/planner/Module.java:[39,11] cannot find symbol
[ERROR] symbol: class Problem
[ERROR] location: class eu.planner.Module
[INFO] 100 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 45.090 s
[INFO] Finished at: 2015-05-02T10:46:45+01:00
[INFO] Final Memory: 21M/219M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project optimizer: Compilation failure: Compilation failure:
[ERROR] /Users/Ste/Desktop/eclip/workspace/planner/src/main/java/eu/planner/heuristics/SVariable.java:[234,9] method does not override or implement a method from a supertype
[ERROR] /Users/Ste/Desktop/eclip/workspace/planner/src/main/java/eu/planner/heuristics/SVariable.java:[237,24] cannot find symbol
[ERROR] symbol: variable super
[ERROR] location: class eu.planner.heuristics.SVariable
[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
添加 -X 会显示 DEBUG,但没什么奇怪的。它只是在末尾添加以下信息:
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project optimizer: Compilation failure
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:108)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:76)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:116)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:361)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:157)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure
at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:858)
at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:129)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:133)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
... 19 more
[ERROR]
[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
我还尝试添加我正在处理的模块的 POM,这个构建助手取自这里 http://mojo.codehaus.org/build-helper-maven-plugin/usage.html(没有成功):
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals><goal>add-source</goal></goals>
<configuration>
<sources>
<source>/Users/Ste/Desktop/externalFolderWithJavaClasses<source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
其中plugin 元素在/project/build/plugins 中,而不在/project/build/pluginManagement/plugins 中。
我检查了项目的target/classes 文件夹,它是空的。
我没有从任何其他项目导入文件。刚刚从我的文件系统链接了一个文件夹。 您在屏幕截图中看到的路径与您在编译错误中看到的不同,因为一开始我认为不显示我的真实路径。 这里有2个截图:
有谁明白什么是错的?非常感谢
附:我使用的是 Mac OS X x64、Eclipse Luna,如果对某人而言,此信息是基础信息,则该项目是从 GitHub 存储库中提取的。
【问题讨论】:
-
您的项目是否从任何其他项目导入文件,因为这就是您遇到 mojo failure 异常的原因
-
我添加了 2 个屏幕截图以澄清我的情况。但是,我没有从任何其他项目导入文件。您在屏幕截图中看到的路径与您在编译错误中看到的不同,因为一开始我认为不显示我的真实路径。
-
我删除了链接源,然后重新添加了它。编译错误消失了,
target/classes现在充满了 .class 文件(也与源文件夹相关)。为什么它只是这样做而没有像 Build-Maven-Helper 建议的那样在 POM 中进行任何奇怪的配置(这对许多其他用户来说是最好的解决方案)?稍后我会写下我的问题的最佳答案,前提是我的新问题(在后者之后出现)将得到解决。新问题:我在 src/test/java 中有 2 个 Java 测试类,但在 mvn:test 中只能识别其中一个。我要为此创建一个新的相关问题
标签: java eclipse maven pom.xml