Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Maven构建编译错误:未能在项目Maven上执行目标org.apache.Maven.plugins:Maven编译器plugin:3.1:compile(默认编译)_Java_Maven_Build_Maven Compiler Plugin - Fatal编程技术网

Java Maven构建编译错误:未能在项目Maven上执行目标org.apache.Maven.plugins:Maven编译器plugin:3.1:compile(默认编译)

Java Maven构建编译错误:未能在项目Maven上执行目标org.apache.Maven.plugins:Maven编译器plugin:3.1:compile(默认编译),java,maven,build,maven-compiler-plugin,Java,Maven,Build,Maven Compiler Plugin,我有一个maven项目,它是从git回购复制到我的eclipse上的。它是基于Java8构建的。我要做的第一件事就是做一个 mvn clean install 但我得到以下失败信息: [INFO] Scanning for projects... [INFO] [INFO] --------------------------------------

我有一个maven项目,它是从git回购复制到我的eclipse上的。它是基于Java8构建的。我要做的第一件事就是做一个

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:

以及汇编设置:

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

更新:

在添加属性以设置maven编译器插件之后

<properties>
 <maven.compiler.source>1.8</maven.compiler.source>
 <maven.compiler.target>1.8</maven.compiler.target>
</properties>
下面是给出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();

            }
        }
    });
}

我认为IDE与此无关。毕竟,您正在运行一个Maven,而Maven没有一个可以编译diamond操作符的源代码。 所以,我认为您应该配置maven编译器插件本身

你可以看看这个。但一般来说,请尝试添加以下属性:

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

1.8
1.8

并查看它现在是否仅在Maven中编译。

发生错误是因为代码不适用于此处使用的默认编译器。在根元素结束之前,在声明依赖项之后,将此代码粘贴到有效的POM中,以更改所使用的编译器。根据需要调整版本

<dependencies>
...
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

...
org.apache.maven.plugins
maven编译器插件
1.8
1.8

在我的例子中,它是由与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

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

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

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

伙计,
如果所有这些都是最新的,即使您遇到了这个问题,那么
尝试直接从终端运行此命令,而不是从eclipse运行。
$mvn干净安装


并确保:

  • maven在系统路径中
  • 所有maven依赖项都可以在“.m2/repository”中找到
  • java在系统路径中


因为java版本不匹配,所以我已经更正了它,并且我能够构建war文件。希望它能帮助其他人

    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
1.7
1.7

在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>

org.apache.maven.plugins
maven编译器插件
2.4
1.8
1.8
  • 更新
    下的pom.xml

  • 更新您的项目

  • 然后清洁maven并安装maven


  • 下面的pom.xml配置使构建成功,并确保project buildpath JRE系统库应指向Java8

    org.apache.maven.pluginsmaven-compiler-plugin3.7.0 1.81.8

    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>
    

    您应该将代码添加到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>
    
    
    UTF-8
    1.8
    1.8
    
    如果您能够从terminal而不是Eclipse check out Window>Preferences>Installed JRE成功编译
    mvn compile
    项目,请确保您选择了JDK下的JRE(在pic中检查两个不同JRE的路径),因为Maven需要JDK来编译,您需要添加它


    转到存储POM的文件位置并打开cmd。 然后键入“mvn--v”检查提供的maven版本和java运行时。 检查运行时属性,如果它是“C:\Program Files\Java\jre1.8.0_191”或更接近JRE,则转到环境变量并添加一个名为“Java_HOME”的新“系统变量”,其值为“C:\Program Files\Java\jdk1.8.0_191”


    重新打开cmd,然后“清洁安装”项目。

    确保java主路径正确。在我的例子中,pom文件中的java主路径是错误的

      <properties>
            <java.home>/usr/java/jdk1.8.0_45/bin/javac</java.home>
      </properties>
    
    
    
    
                  <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-compiler-plugin</artifactId>
                            <version>3.5.1</version>
                    <configuration>
                          <verbose>true</verbose>
                          <fork>true</fork>
                          <executable>${java.home}</executable>
                       <compilerVersion>1.8</compilerVersion>
                       <source>1.8</source>
                       <target>1.8</target>
                     </configuration>
                 </plugin>
    
    <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>
    
    
    /usr/java/jdk1.8.0_45/bin/javac
    org.apache.maven.plugins
    maven编译器插件
    3.5.1
    真的
    真的
    ${java.home}
    1.8
    1.8
    1.8
    
    我无法根据其他建议运行自己的构建。我甚至尝试了maven编译器插件的不同版本:3.1、3.7.0等等

    我成功地添加了以下内容:

    <testSourceDirectory>/src/test/java</testSourceDirectory>
    
    /src/test/java
    
    我尝试了这种方法,因为似乎/src/test/java目录被认为是一个java类,这就是为什么它与/src/test/java同时编译的原因。所以我的直觉对我来说是正确的


    也许对其他人也是如此,所以试试这个吧。

    这是一个令人恼火的错误,偶尔会弹出,记下一些有用的步骤:

    从eclipse的角度编写答案作为基本逻辑仍然是最重要的 无论是通过Intellij还是命令行执行,都相同

  • Rt单击您的项目->Maven->更新项目->选择强制 更新->单击确定
  • 在“属性”标记下,添加:

  • 我的问题是,我从子项目目录而不是父项目目录运行
    mvn compile

    如果您的本地jdk版本是11或9、10,并且您的项目的java源/目标版本是1.8,并且您使用的是
    org.projectlombok:lombok
    包,然后您可以尝试将其版本更新为1.16.22或1.18.12,如下所示:

            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>1.16.22</version>
            </dependency>
    
    
    org.projectlombok
    龙目
    1.16.22
    

    它刚刚解决了我的问题。

    我也遇到了同样的问题,解决方案是在环境变量中设置JAVA_HOME。

    通过添加此
    <maven.compiler.source>1.8</maven.compiler.source> 
    <maven.compiler.target>1.8</maven.compiler.target>
    
    for /r %i in (*.lastUpdated) do del %i
    
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>1.16.22</version>
            </dependency>
    
    <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>
    
    <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>