Java Maven 构建编译错误:无法在项目 Maven 上执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42525139/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Maven build Compilation error : Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project Maven
提问by roger_that
I have a maven project forked and cloned from a git repo onto my eclipse. It is build on Java 8. The first thing i do is perform a
我有一个 maven 项目,从 git repo 分叉并克隆到我的 eclipse 上。它建立在 Java 8 之上。我做的第一件事是执行一个
mvn clean install
But I get following failure message:
但我收到以下失败消息:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ Maven ---
[INFO] Deleting /Users/vshukla/git/Prism/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Maven ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/vshukla/git/Prism/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ Maven ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 66 source files to /Users/vshukla/git/Prism/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Users/vshukla/git/Prism/src/main/java/PrenPost/scanUtility.java:[54,52] diamond operator is not supported in -source 1.5
(use -source 7 or higher to enable diamond operator)
[ERROR] /Users/vshukla/git/Prism/src/main/java/main/AppUtility.java:[87,86] diamond operator is not supported in -source 1.5
(use -source 7 or higher to enable diamond operator)
[ERROR] /Users/vshukla/git/Prism/src/main/java/PrenPost/ComparisionUtility.java:[58,52] diamond operator is not supported in -source 1.5
(use -source 7 or higher to enable diamond operator)
[INFO] 3 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.266 s
[INFO] Finished at: 2017-03-01T12:11:27+05:30
[INFO] Final Memory: 13M/309M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project Maven: Compilation failure: Compilation failure:
[ERROR] /Users/vshukla/git/Prism/src/main/java/PrenPost/scanUtility.java:[54,52] diamond operator is not supported in -source 1.5
[ERROR] (use -source 7 or higher to enable diamond operator)
[ERROR] /Users/vshukla/git/Prism/src/main/java/main/AppUtility.java:[87,86] diamond operator is not supported in -source 1.5
[ERROR] (use -source 7 or higher to enable diamond operator)
[ERROR] /Users/vshukla/git/Prism/src/main/java/PrenPost/ComparisionUtility.java:[58,52] diamond operator is not supported in -source 1.5
[ERROR] (use -source 7 or higher to enable diamond operator)
[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
However, below is the build path details of the project which clearly has JRE - 8 set up:
但是,以下是该项目的构建路径详细信息,其中明确设置了 JRE - 8:
and the compilation set up:
和编译设置:
No matter how many times I build the project, i get the same error. Even after cleaning the project and refreshing it from eclipse doesn't help. Please guide.
无论我构建项目多少次,我都会遇到同样的错误。即使在清理项目并从 Eclipse 刷新之后也无济于事。请指导。
UPDATE:
更新:
After adding the properties to set maven compiler plugin
添加属性后设置maven编译器插件
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
,
,
am getting the below error:
我收到以下错误:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ Maven ---
[INFO] Deleting /Users/vshukla/git/Prism/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Maven ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/vshukla/git/Prism/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ Maven ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 66 source files to /Users/vshukla/git/Prism/target/classes
[INFO] -------------------------------------------------------------
[WARNING] COMPILATION WARNING :
[INFO] -------------------------------------------------------------
[WARNING] /Users/vshukla/git/Prism/src/main/java/main/MainUITabbed.java: /Users/vshukla/git/Prism/src/main/java/main/MainUITabbed.java uses or overrides a deprecated API.
[WARNING] /Users/vshukla/git/Prism/src/main/java/main/MainUITabbed.java: Recompile with -Xlint:deprecation for details.
[WARNING] /Users/vshukla/git/Prism/src/main/java/main/MainUITabbed.java: Some input files use unchecked or unsafe operations.
[WARNING] /Users/vshukla/git/Prism/src/main/java/main/MainUITabbed.java: Recompile with -Xlint:unchecked for details.
[INFO] 4 warnings
[INFO] -------------------------------------------------------------
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Users/vshukla/git/Prism/src/main/java/main/MainUITabbed.java:[26,22] package com.apple.eawt does not exist
[ERROR] /Users/vshukla/git/Prism/src/main/java/main/MainUITabbed.java:[93,41] cannot find symbol
symbol: class Application
[ERROR] /Users/vshukla/git/Prism/src/main/java/main/MainUITabbed.java:[93,67] cannot find symbol
symbol: variable Application
[INFO] 3 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.591 s
[INFO] Finished at: 2017-03-01T13:09:47+05:30
[INFO] Final Memory: 21M/347M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project Maven: Compilation failure: Compilation failure:
[ERROR] /Users/vshukla/git/Prism/src/main/java/main/MainUITabbed.java:[26,22] package com.apple.eawt does not exist
[ERROR] /Users/vshukla/git/Prism/src/main/java/main/MainUITabbed.java:[93,41] cannot find symbol
[ERROR] symbol: class Application
[ERROR] /Users/vshukla/git/Prism/src/main/java/main/MainUITabbed.java:[93,67] cannot find symbol
[ERROR] symbol: variable Application
[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
And here is the code snippet giving the compilation error from MainUITabbed class:
这是给出 MainUITabbed 类编译错误的代码片段:
import com.apple.eawt.Application;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Application application = Application.getApplication(); // line 93
ImageIcon imgicon = new ImageIcon(getClass().getResource(
"ICON.jpg"));
Image img = imgicon.getImage();
application.setDockIconImage(img);
MainUITabbed frame = new MainUITabbed();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
回答by Mark Bramnik
I don't think that IDE is relevant here. After all you're running a Maven and Maven doesn't have a source that will allow to compile the diamond operators. So, I think you should configuration maven-compiler-plugin itself.
我认为 IDE 在这里无关紧要。毕竟,您正在运行 Maven,而 Maven 没有允许编译菱形运算符的源。所以,我认为你应该配置 maven-compiler-plugin 本身。
You can read about this here. But in general try to add the following properties:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
and see whether it compiles now in Maven only.
并查看它现在是否仅在 Maven 中编译。
回答by user7639880
The error occurred because the code is not for the default compiler used there. Paste this code in effective POM before the root element ends, after declaring dependencies, to change the compiler used. Adjust version as you need.
发生错误是因为代码不适用于那里使用的默认编译器。在声明依赖项之后,在根元素结束之前将此代码粘贴到有效 POM 中,以更改使用的编译器。根据需要调整版本。
<dependencies>
...
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
回答by snovelli
In my case, it was caused from an incompatibility with OpenJDK 9 (which I haven't investigated).
就我而言,它是由与 OpenJDK 9 不兼容引起的(我没有调查过)。
If you don't need JDK 9, a temporary work-around would be to purge it from your machine:
如果您不需要 JDK 9,临时解决方法是将其从您的机器中清除:
sudo apt-get remove --purge openjdk-9-jdk openjdk-9-jre
sudo apt-get remove --purge openjdk-9-jdk-headless openjdk-9-jre-headless
回答by chamzz.dot
I had the same problem and I Changed this
我有同样的问题,我改变了这个
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
here 1.7 is my JDK version.it was solved.
这里 1.7 是我的 JDK 版本。它已解决。
回答by nityanarayan44
Buddy,
If every this is up-to-date, even then you are having this problem, then
try running this command from the terminal directly instead of running from eclipse.$ mvn clean install
and make sure these things:
伙计,
如果每一个都是最新的,即使你遇到了这个问题,那么
尝试直接从终端运行这个命令,而不是从 eclipse 运行。$ mvn clean install
并确保这些事情:
- maven is in system path
- all maven dependencies are avaialble at `.m2/repository`
- java is in system path
- maven 在系统路径中
- 所有 Maven 依赖项都可以在 `.m2/repository` 中获得
- java在系统路径中
回答by Rajib Naik From CGI
for it was comming because of java version mismatch ,so I have corrected it and i am able to build the war file.hope it will help someone
因为它是因为 java 版本不匹配而出现的,所以我已经更正了它并且我能够构建战争文件。希望它会帮助某人
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
回答by Sushovan Mallick
Doing this in pom.xml file and after updating the project, the problem is gone.
在 pom.xml 文件中执行此操作并更新项目后,问题就消失了。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.4</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
Update the pom.xml under
<plugin></plugin>
.Update your project.
Then clean maven and install maven.
更新 .xml 下的 pom.xml
<plugin></plugin>
。更新您的项目。
然后清理maven并安装maven。
回答by Srinivas Avasarala
The below pom.xml configuration is making the build successful and make sure project buildpath JRE System library should point to Java8.
下面的 pom.xml 配置使构建成功并确保项目构建路径 JRE 系统库应该指向 Java8。
org.apache.maven.pluginsmaven-compiler-plugin3.7.0 1.81.8
org.apache.maven.pluginsmaven-compiler-plugin3.7.0 1.81.8
回答by vsingh
Jdk 9 and 10 solution
Jdk 9 和 10 解决方案
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<debug>true</debug>
</configuration>
<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>6.2</version>
</dependency>
</dependencies>
</plugin>
and make sure your maven is pointing to JDK 10 or 9. mvn -v
并确保您的 Maven 指向 JDK 10 或 9。 mvn -v
Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-24T14:49:05-05:00)
Maven home: C:\devplay\apache-maven-3.5.3\bin\..
Java version: 10.0.1, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk-10.0.1
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
回答by user8961607
You should add the code into pom.xml like:
您应该将代码添加到 pom.xml 中,例如:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>