2017-03-01 166 views
6

我有一个maven项目分叉和从git repo克隆到我的日食。它是建立在Java的8的第一件事情我做的是执行Maven build编译错误:无法执行目标org.apache.maven.plugins:maven-compiler-plugin:3.1:编译(默认编译)项目Maven

mvn clean install 

,但我得到以下故障消息:

[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 

然而,下面是这显然有项目的构建路径的详细信息JRE - 8设置: build path

和编译设置:

Compliance level

无论我多少次构建项目,我都会得到同样的错误。即使在清理项目并从日食中刷新它也没有帮助。请指导。

UPDATE:

后增加的属性设置maven的编译器插件

<properties> 
<maven.compiler.source>1.8</maven.compiler.source> 
<maven.compiler.target>1.8</maven.compiler.target> 
</properties> 

我得到下面的错误:

[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 

这里是给compi的代码片段来自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(); 

      } 
     } 
    }); 
} 
+2

您是否有依赖关系: ' com.apple AppleJavaExtensions 1.4 '在你的pom.xml? – DrHopfen

+0

不,让我试试。 –

+0

辉煌。有效。但是如何?为什么是这个错误? –

回答

4

我不认为IDE在这里是相关的。毕竟你正在运行一个maven,而maven没有一个可以编译钻石操作员的源代码。 所以,我认为你应该配置Maven的编译器插件本身

您可以了解这个here

但总的来说尝试添加以下属性:

<properties> 
<maven.compiler.source>1.8</maven.compiler.source> 
<maven.compiler.target>1.8</maven.compiler.target> 
</properties> 

,看看它是否编译现在在maven只有

希望这可以帮助

+0

请参阅编辑。 –

17

将此添加到聚甲醛固定它fo我。请根据需要调整版本

... 
</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> 
+0

请参阅编辑。 –

1

在我的情况下,它是由于与OpenJDK 9(我没有调查过)不兼容而导致的。

如果您不需要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 
0

我有同样的问题,我改变了这个

<configuration> 
    <source>1.7</source> 
    <target>1.7</target> 
</configuration> 

这里1.7是我的JDK版本,已经解决了。

1

好友,
如果每个这是跟上时代的,即使如此,你是有这个问题,然后
尝试从终端运行此命令,而不是直接从Eclipse中运行。
$ mvn clean install

,并确保这些东西:

  • Maven是在系统路径
  • 所有Maven的依赖是在avaialble`.m2目录/ repository`
  • Java是在系统路径


相关问题