Maven不能编译java 1.8 [英] Maven can't compile java 1.8

查看:686
本文介绍了Maven不能编译java 1.8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  ERROR]无法执行目标org.apache.maven.plugins:maven-compiler-plugin:3.1:在项目上编译
(default-compile)应用程序:致命错误编译:无效的目标版本:1.8 - > [帮助1]
[ERROR]
[ERROR]要查看错误的完整堆栈跟踪,请使用-e开关重新运行Maven。
[ERROR]使用-X开关重新运行Maven以启用完整的调试日志记录。
[ERROR]
[ERROR]有关错误和可能的解决方案的更多信息,请阅读以下文章:
[错误] [帮助1] http://cwiki.apache.org / confluence / display / MAVEN / MojoExecutionException

mvn -v输出

  mvn -version 
Apache Maven 3.2.5(12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-14T09:29:23-08:00)
Maven首页:/usr/local/Cellar/maven/3.2.5/libexec
Java版本:1.6.0_65,供应商:Apple Inc.
Java主页:/System/Library/Java/JavaVirtualMachines/1.6.0 .jdk / Contents / Home
默认语言环境:en_US,平台编码:MacRoman
操作系统名称:mac os x,版本:10.10.1,arch:x86_64,family:mac

所以看起来它指向1.6jdk



但我有1.8 jdk



java -version

  java -version 
java版本1.8.0_25
Java(TM)SE运行时环境(build 1.8.0_25-b17)
Java HotSpot(TM)64位服务器虚拟机(构建25.25-b02,混合模式)

POM.xml

 < project xmlns =http://maven.apache.org/POM/4.0.0xmlns :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.brian.ridecellchallenge< / groupId>
< artifactId>应用程序< / artifactId>
< version> 0.0.1-SNAPSHOT< / version>
< build>
< sourceDirectory> src< / sourceDirectory>
< plugins>
< plugin>
< artifactId> maven-compiler-plugin< / artifactId>
< version> 3.1< / version>
< configuration>
< source> 1.8< / source>
< target> 1.8< / target>
< / configuration>
< / plugin>

< plugin>
< groupId> org.apache.maven.plugins< / groupId>
< artifactId> maven-shade-plugin< / artifactId>
< version> 1.6< / version>
<执行>
< execution>
< phase> package< / phase>
< goals>
< goal> shade< / goal>
< / goals>
< configuration>
<变压器>
< transformer
implementation =org.apache.maven.plugins.shade.resource.ManifestResourceTransformer>
< mainClass> com.group.id.Launcher1< / mainClass>
< / transformer>
< / transformers>
< / configuration>
< / execution>
< / executions>
< / plugin>
< / plugins>


< / build>
<依赖关系>
<依赖关系>
< groupId> junit< / groupId>
< artifactId> junit< / artifactId>
< version> 4.12< / version>
< scope> test< / scope>
< / dependency>

<依赖关系>
< groupId> commons-io< / groupId>
< artifactId> commons-io< / artifactId>
< version> 2.4< / version>
< / dependency>
<依赖关系>
< groupId> joda-time< / groupId>
< artifactId> joda-time< / artifactId>
< version> 2.6< / version>
< / dependency>
< / dependencies>
< / project>


解决方案

Maven依赖于设置的JAVA_HOME环境变量。根据您的操作系统进行设置并重新运行构建。



编辑:
使用导出设置变量。

  export JAVA_HOME = / path / to / java 


I'm trying to use maven to build a jar but I keep getting the error

ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile 
(default-compile) on project Application: Fatal error compiling: invalid target release: 1.8 -> [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/MojoExecutionException

mvn -v outputs

mvn -version
Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-14T09:29:23-08:00)
Maven home: /usr/local/Cellar/maven/3.2.5/libexec
Java version: 1.6.0_65, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x", version: "10.10.1", arch: "x86_64", family: "mac"

So it looks like its pointing to the 1.6jdk

but I have the 1.8 jdk

java -version

java -version
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

POM.xml

 <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.brian.ridecellchallenge</groupId>
    <artifactId>Application</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>1.6</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>com.group.id.Launcher1</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>


    </build>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
        </dependency>
        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>2.6</version>
        </dependency>
    </dependencies>
</project>

解决方案

Maven relies on the JAVA_HOME environment variable being set. Set it according to your OS and re-run your build.

Edit: Use export to set the variable.

export JAVA_HOME=/path/to/java

这篇关于Maven不能编译java 1.8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆