Grails 2.2.0应用程序的Maven构建失败,JDK 1.7:无法找到工件com.sun:tools:jar:1.6

时间:2013-02-23 04:33:20

标签: maven grails maven-3

(由于更新的问题/问题更新了问题标题,请参阅底部的更新说明!):

我有一个Grails 2.2.0项目,通过“grails create-pom com.mycompany”为它创建了pom.xml。

pom.xml:http://pastebin.com/AVahZjZF

如果不对pom.xml进行修改,我使用 JDK 1.7 运行“mvn package”并获得以下错误,而使用 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

我看到java版本在grails-maven-plugin-2.2.0.pom中设置为1.6,因此我现在的问题是:如何使我的grails项目的maven构建与JDK 1.7一起工作?看起来好像在maven-compiler-plugin中设置了正确的源和目标级别(设置为1.6)。

文件夹〜/ .m2 / repository / grails-maven-plugin:

enter image description here

我的环境:

  • Maven 3.0.3
  • Grails 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>

3 个答案:

答案 0 :(得分:3)

这似乎是一个已知问题,据报道仍然在Mac OS X上的Grails 2.2.0中发生。

http://jira.grails.org/browse/MAVEN-186

答案 1 :(得分:2)

<强>更新

如@Mathias所述,这是Grails Maven插件中的一个错误。这个问题已得到修复,并且在Grails 2.2.1中一切正常。


我绝对可以使用 mvn package 来自Homebrew的Grails 2.2.0,* GRAILS_HOME *未设置。

我的配置是Maven 3.0.3,在OSX上使用Grails 2.2.0。

我毫无困难地创建了一个“空白”香草应用程序并将其打包。

grails create-app stf && cd stf
grails create-pom com.rimerosolutions.grails
mvn package

在我的 pom.xml 中, grails-maven-plugin 的版本设置为$ {grails.version}。

我正在运行OSX,看起来你也在运行它。

  • 您使用的是私有maven存储库吗?如果是这样,请尝试仔细检查 那里有grails-maven-plugin工件。
  • 如果没有,只需尝试清除grails-maven-plugin的〜/ .m2 / repository 内容。 rm -rf 该特定插件缓存。

答案 2 :(得分:0)

问题在于grails-maven-plugin表示它需要JDK6中的内容:

tail -n20 ~/.m2/repository/org/grails/grails-maven-plugin/2.0.3/grails-maven-plugin-2.0.3.pom
    <profile>
        <id>jdk_mac</id>
        <activation>
            <os>
                <family>mac</family>
            </os>
        </activation>
        <dependencies>
            <dependency>
                <groupId>com.sun</groupId>
                <artifactId>tools</artifactId>
                <version>1.6</version>
                <scope>system</scope>
                <systemPath>${java.home}/bundle/Classes/classes.jar</systemPath>
            </dependency>
        </dependencies>
    </profile>
</profiles>

解决方案是将JDK6 classes.jar复制到当前的JDK中。幸运的是,JDK7使用不同的目录结构,所以不应该有任何冲突。

sudo mkdir -p /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre/bundle/Classes
sudo cp /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Classes/classes.jar /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre/bundle/Classes/