在Mac上安装Java 7时,javac目标1.7 mvn无效

在Mac上安装Java 7时,javac目标1.7 mvn无效,java,macos,maven,javac,Java,Macos,Maven,Javac,我下载了一个Github项目,我的团队将为其进行开发工作(它是私有的,所以共享它不会有帮助)。 它包括具有以下依赖项的pom.xml文件: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2&l

我下载了一个Github项目,我的团队将为其进行开发工作(它是私有的,所以共享它不会有帮助)。 它包括具有以下依赖项的pom.xml文件:

 <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-compiler-plugin</artifactId>
         <version>2.3.2</version>
         <configuration>
              <source>1.7</source>
              <target>1.7</target>
             <showDeprecation>true</showDeprecation>
            <showWarnings>true</showWarnings>
         </configuration>
 </plugin>
看起来我的Mac上成功安装了Java 7,Java_HOME的环境变量设置正确,maven声称拥有我需要的Java版本

在我从Github克隆的那个项目的顶级目录中,我将其称为“githubproject”,我运行:

它运行,有一段时间输出良好。。。在此之前:

[INFO] Compiling 239 source files to /usr/local/gardens/githubproject/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] Failure executing javac, but could not parse the error:
javac: invalid target release: 1.7
Usage: javac <options> <source files>
use -help for a list of possible options

[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 18.793 s
[INFO] Finished at: 2014-06-05T13:08:38-05:00
[INFO] Final Memory: 26M/123M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project hgtvgardens: Compilation failure
[ERROR] Failure executing javac, but could not parse the error:
[ERROR] javac: invalid target release: 1.7
[ERROR] Usage: javac <options> <source files>
[ERROR] use -help for a list of possible options
[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
它修复了他的构建错误——但他遇到的问题与项目编译错误的问题相同

其他团队成员完全没有问题-相同的操作系统、硬件、Github项目和软件。。。有些事情是不同的-我不知道是什么

Mavan编译器插件更新 有人建议使用更新的maven编译器

从下载maven-compiler-plugin-3.1.jar 并将其复制到我的apachemaven/lib目录中(这是一个完整的猜测)。 然后我更新了pom.xml以使用3.1而不是2.3.2

结果是:

[ERROR] Failed to execute goal 
org.apache.maven.plugins:maven-compiler-plugin:3.1:compile 
(default-compile) on project githubproject: Execution default-compile of goal 
org.apache.maven.plugins:maven-compiler-plugin:3.1:compile failed: 
A required class was missing while executing 
org.apache.maven.plugins:maven-compiler-plugin:3.1:compile: 
org/codehaus/plexus/compiler/util/scan/mapping/SuffixMapping
我可能做错了

(我的)答案 我明白了-权限不允许访问该Github项目中的文件。我只需要更改这些文件的权限,它就成功地构建了。 (将编译器插件放在我的mavin lib目录下会使maven崩溃一段时间,但我最终摆脱了那个位置不正确的jar)。
感谢所有关注此事的人——这个错误只是一个转移视线的问题。

我已经完全用直接从Sun下载的1.7取代了我的Mac OS Java。它确实需要对指向
CurrentJDK
的链接进行一些修改,但结果如下。希望这会有所帮助,因为您的Java安装似乎在某种程度上被破坏了:

哪个操作系统:

System Version: OS X 10.9.3 (13D65)
Kernel Version: Darwin 13.2.0
我有哪些java以及它在哪里:

schroedinger:backend olegs$ javac -version
javac 1.7.0_40

schroedinger:backend olegs$ which javac
/usr/bin/javac
那么,它实际安装在哪里以及如何安装:

schroedinger:Versions olegs$ ls -la /usr/bin/javac
lrwxr-xr-x  1 root  wheel  75 31 Okt  2013 /usr/bin/javac -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/javac

schroedinger:Versions olegs$ pwd
/System/Library/Frameworks/JavaVM.framework/Versions
在当前的
下,哪个JVM实际在那里。注意有
CurrentJDK
(指向不同位置的1.6)和
Current
(指向1.7)。实际的1.7 JDK安装在目录1.7中:

schroedinger:Versions olegs$ ls -la
total 64
drwxr-xr-x  11 root  wheel  374 31 Okt  2013 .
drwxr-xr-x  12 root  wheel  408 21 Apr 19:42 ..
lrwxr-xr-x   1 root  wheel   10 31 Okt  2013 1.4 -> CurrentJDK
lrwxr-xr-x   1 root  wheel   10 31 Okt  2013 1.4.2 -> CurrentJDK
lrwxr-xr-x   1 root  wheel   10 31 Okt  2013 1.5 -> CurrentJDK
lrwxr-xr-x   1 root  wheel   10 31 Okt  2013 1.5.0 -> CurrentJDK
lrwxr-xr-x   1 root  wheel   10 31 Okt  2013 1.6 -> CurrentJDK
lrwxr-xr-x   1 root  wheel   10 31 Okt  2013 1.6.0 -> CurrentJDK
drwxr-xr-x   8 root  wheel  272 31 Okt  2013 1.7
lrwxr-xr-x   1 root  wheel    1 31 Okt  2013 Current -> 1.7
lrwxr-xr-x   1 root  wheel   59 31 Okt  2013 CurrentJDK -> /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents
我的pom怎么说:

schroedinger:backend olegs$ grep jdk.version pom.xml 
    <jdk.version>1.7</jdk.version>

...    
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>${jdk.version}</source>
                <target>${jdk.version}</target>
            </configuration>
我的专业是什么?它与
自制软件一起安装

schroedinger:backend olegs$ which mvn
/usr/local/bin/mvn

schroedinger:backend olegs$ ls -la /usr/local/bin/mvn
lrwxr-xr-x  1 dev  staff  29 31 Okt  2013 /usr/local/bin/mvn -> ../Cellar/maven/3.0.5/bin/mvn
它编译吗

schroedinger:backend olegs$ mvn clean install
[INFO] Scanning for projects...
[INFO]                                 
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.407s
[INFO] Finished at: Thu Jun 05 20:35:48 CEST 2014

请使用更新版本的。(顺便说一句:你为什么要通过sudo给mvn打电话?)。也有这种可能性,你可以试试awnsers,看看这是否有帮助。(PS:你们是在共享maven安装吗?!)@khmarbaise我在一台工作计算机上,偶尔会遇到一些奇怪的权限问题——只需要四处走动和清理一下,但我怀疑通过sudo运行它是不是个问题。将介绍如何使用更新的maven编译器。我应该把plugin.jar放在哪里?@ug\u我读了并检查了它-看起来它应该有一个合适的JAVA\u主页,特别是因为我正在定义它。如果脚本也符合任何逻辑,它将输出一些内容。。。因此,mvn脚本似乎不是用错误的Java重写的,我们都单独安装了maven,但都安装了相同的版本(因此,是的,我们都使用相同的maven安装,但不一定是数字相同的文件…因此,我们有不同的mvn安装,这将是一种边缘情况)。尝试了3.1编译器插件(更新了pom.xml,改为3.1,而不是2.3.2),将用输出更新主描述…您将maven编译器3.1 jar放在哪里了?所以您没有使用单独的编译器插件?当然没有。您在pom中指定要使用特定版本的插件和maven(在
mvm clean install
期间)自动从web上为您拉入它。就像任何其他依赖项一样:
/Users/olegs/.m2/repository/org/apache/maven/plugins/maven compiler plugin/3.1
啊,这就清除了问题-所以我不需要安装编译器。很好-那么问题就不存在了。结果如何?
schroedinger:backend olegs$ grep jdk.version pom.xml 
    <jdk.version>1.7</jdk.version>

...    
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>${jdk.version}</source>
                <target>${jdk.version}</target>
            </configuration>
schroedinger:backend olegs$ echo $JAVA_HOME
schroedinger:backend olegs$ which mvn
/usr/local/bin/mvn

schroedinger:backend olegs$ ls -la /usr/local/bin/mvn
lrwxr-xr-x  1 dev  staff  29 31 Okt  2013 /usr/local/bin/mvn -> ../Cellar/maven/3.0.5/bin/mvn
schroedinger:backend olegs$ mvn clean install
[INFO] Scanning for projects...
[INFO]                                 
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.407s
[INFO] Finished at: Thu Jun 05 20:35:48 CEST 2014