Usando javah maven-antrun-plugin con jdk 1.7, classes.jar se convirtió en tools.jar

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 Location: /Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/lib/tools.jar

1.6 Location: /Library/Java/JavaVirtualMachines/1.6.0_32-b05-420.jdk/Contents/Classes/classes.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:

JDK tools.jar como dependencia de maven

maven: ¿Cómo cargar tools.jar / classes.jar de forma independiente del sistema operativo?

Any work around until the maven folks address the maven-antrun-plugin with jdk-1.7 on mac?

preguntado el 02 de julio de 12 a las 08:07

1 Respuestas

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>

Respondido 02 Jul 12, 09:07

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.