使用带有jdk 1.7的javah maven-antrun-plugin,classes.jar成为tools.jar

时间:2012-07-02 07:54:56

标签: maven maven-antrun-plugin

在Mac的jdk 1.7中,com.sun.tools.javah.Main的位置从classes.jar移动到tools.jar。因此,Maven的maven-antrun-plugin无法找到运行javah任务并抛出ClassNotFound异常:

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.6地点:/ Library/Java/JavaVirtualMachines/1.6.0_32-b05-420.jdk/Contents/Classes/classes.jar

这似乎是maven版本3.0.4的错误或失败。我认为使tools.jar成为一个插件依赖项,但这似乎并不合适。我试过这些解决方案,但我无法让它们起作用:

JDK tools.jar as maven dependency

maven: How to load tools.jar/classes.jar in an OS independent way?

任何解决方案,直到maven人在Mac上使用jdk-1.7解决maven-antrun-plugin?

1 个答案:

答案 0 :(得分:1)

答案是将tools.jar添加为插件的依赖项。在<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>