(由于更新的问题/问题而更新了问题标题,请参阅底部的更新说明!):
我有一个 Grails 2.2.0 项目,通过“ grails create-pom com.mycompany
”为它创建了 pom.xml。
pom.xml: http: //pastebin.com/AVahZjZF
在不修改 pom.xml 的情况下,我mvn package
使用JDK 1.7运行“”并得到以下错误,而使用JDK 1.6则可以正常工作。
$ java -version
java version "1.7.0_11"
Java(TM) SE Runtime Environment (build 1.7.0_11-b21)
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)
$ mvn -version
Apache Maven 3.0.3 (r1075438; 2011-03-01 01:31:09+0800)
Maven home: /usr/share/maven
Java version: 1.7.0_11, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_11.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.7.4", arch: "x86_64", family: "mac"
$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_11.jdk/Contents/Home
$ mvn package
[INFO] Scanning for projects...
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project com.company:company-projectname:0.1 (/Users/myuser/Projects/com.company.web/pom.xml) has 2 errors
[ERROR] Unresolveable build extension: Plugin org.grails:grails-maven-plugin:2.2.0 or one of its dependencies could not be resolved: Could not find artifact com.sun:tools:jar:1.6 at specified path /Library/Java/JavaVirtualMachines/jdk1.7.0_11.jdk/Contents/Home/jre/bundle/Classes/classes.jar -> [Help 2]
[ERROR] Unknown packaging: grails-app @ line 8, column 16
[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/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException
我看到 grails-maven-plugin-2.2.0.pom 中的 java 版本设置为 1.6,因此我现在的问题是:如何使我的 grails 项目的 maven 构建与 JDK 1.7 一起工作?看起来好像在 maven-compiler-plugin 中设置了正确的源和目标级别(设置为 1.6)。
文件夹 ~/.m2/repository/grails-maven-plugin:
我的环境:
- Maven 3.0.3
- 圣杯 2.2.0
- GRAILS_HOME 设置为我的 Grails 目录
- JAVA_HOME 设置为我的 JDK 1.7 文件夹
- JDK 1.7.0_11
我的 pom.xml 中的相关 java 工具部分:
<profiles>
<profile>
<id>tools</id>
<activation>
<property>
<name>java.vendor</name>
<value>Sun Microsystems Inc.</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>${java.version}</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
</profile>
</profiles>