问题描述
在Mac的jdk 1.7中,com.sun.tools.javah.Main的位置从classes.jar移到tools.jar.因此,Maven的maven-antrun-plugin无法找到运行javah任务,并抛出ClassNotFound异常:
In jdk 1.7 for the Mac, the location of com.sun.tools.javah.Main moved from classes.jar to tools.jar. Consequently, Maven's maven-antrun-plugin cannot find the run the javah task and a ClassNotFound exception is thrown:
Caused by: java.lang.ClassNotFoundException: com.sun.tools.javah.Main
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java :50)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:244)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:230)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
at org.apache.tools.ant.taskdefs.optional.javah.SunJavah.compile(SunJavah.java:57)
... 47 more
1.7位置:/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/lib/tools.jar
1.7 Location: /Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/lib/tools.jar
1.6位置:/Library/Java/JavaVirtualMachines/1.6.0_32-b05-420.jdk/Contents/Classes/classes.jar
1.6 Location: /Library/Java/JavaVirtualMachines/1.6.0_32-b05-420.jdk/Contents/Classes/classes.jar
这似乎是Maven版本3.0.4的错误或失败.我考虑过将tools.jar设为插件依赖项,但这似乎并不正确.我尝试了这些解决方案,但无法使它们起作用:
This seems like a bug or failure of maven version 3.0.4. I considered making tools.jar a plugin dependency, but that just doesn't seem right. I tried these solutions, but I couldn't get them to work:
maven:如何以操作系统独立的方式加载tools.jar/classes.jar?
在Mac上使用jdk-1.7解决Maven人员解决Maven-antrun-plugin之前,是否需要解决?
Any work around until the maven folks address the maven-antrun-plugin with jdk-1.7 on mac?
推荐答案
答案是将tools.jar添加为插件的依赖项.包括<dependencies> ... </dependencies>
The answer was to add the tools.jar as a dependency of the plugin. Include the part below from <dependencies> ... </dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>compile</phase>
<configuration>
<target>
<property name="runtime_classpath" refid="maven.runtime.classpath"/>
<property name="test_classpath" refid="maven.test.classpath"/>
<property name="plugin_classpath" refid="maven.plugin.classpath"/>
<echo message="runtime classpath: ${runtime_classpath}"/>
<echo message="test classpath: ${test_classpath}"/>
<echo message="plugin classpath: ${plugin_classpath}"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.7</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
这篇关于结合使用javah maven-antrun-plugin和jdk 1.7,classes.jar成为tools.jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!