使用JAVAH Maven的antrun-插件使用JDK 1.7,classes.jar成为的too

2019-10-16 22:32发布

在JDK 1.7适用于Mac,com.sun.tools.javah.Main的位置,距离classes.jar搬到tools.jar中。 因此,Maven的Maven的antrun-插件无法找到运行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作为Maven的依赖

行家:如何加载的tools.jar / classes.jar在OS独立的方式?

任何工作,直到周围的乡亲行家解决Maven的antrun-插件兼容Mac JDK-1.7?

Answer 1:

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>


文章来源: Using javah maven-antrun-plugin with jdk 1.7, classes.jar became tools.jar