When executing native:javah goal from within Eclipse, I get "error in opening zip file".
When executing the Maven target, "Resolve Workspace artifacts" and "Debug Output" are enabled.
I have attached an example project illustrating the bug.
—
Apache Maven 3.0-alpha-4 (r835944; 2009-11-13 19:06:31+0100)
Java version: 1.6.0_0
Java home: /usr/lib/jvm/java-6-openjdk/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux" version: "2.6.31-15-generic" arch: "amd64" Family: "unix"
[INFO] Error stacktraces are turned on.
[DEBUG] Reading user settings from /home/peter/.m2/settings.xml
[DEBUG] Reading global settings from EMBEDDED/conf/settings.xml
[DEBUG] Using local repository at /home/peter/.m2/repository
[INFO] Scanning for projects...
[DEBUG] Created new class realm extension>org.codehaus.mojo:native-maven-plugin:1.0-alpha-3
[DEBUG] Populating extension realm for org.codehaus.mojo:native-maven-plugin:1.0-alpha-3
[DEBUG] Included: org.codehaus.mojo:native-maven-plugin:maven-plugin:1.0-alpha-3
[DEBUG] Excluded: org.apache.maven:maven-project:jar:2.0.6
[DEBUG] Excluded: org.apache.maven:maven-settings:jar:2.0.6
[DEBUG] Excluded: org.apache.maven:maven-model:jar:2.0.6
[DEBUG] Included: org.codehaus.plexus:plexus-utils:jar:1.5.6
[DEBUG] Excluded: org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9
[DEBUG] Excluded: classworlds:classworlds:jar:1.1-alpha-2
[DEBUG] Excluded: org.apache.maven:maven-profile:jar:2.0.6
[DEBUG] Excluded: org.apache.maven:maven-artifact-manager:jar:2.0.6
[DEBUG] Excluded: org.apache.maven:maven-repository-metadata:jar:2.0.6
[DEBUG] Excluded: org.apache.maven:maven-artifact:jar:2.0.6
[DEBUG] Excluded: org.apache.maven.wagon:wagon-provider-api:jar:1.0-beta-2
[DEBUG] Excluded: org.apache.maven:maven-plugin-registry:jar:2.0.6
[DEBUG] Excluded: org.apache.maven:maven-plugin-api:jar:2.0.6
[DEBUG] Included: bcel:bcel:jar:5.1
[DEBUG] Included: org.codehaus.mojo.natives:maven-native-api:jar:1.0-alpha-3
[DEBUG] Included: org.codehaus.mojo.natives:maven-native-javah:jar:1.0-alpha-3
[DEBUG] Included: commons-lang:commons-lang:jar:2.4
[DEBUG] Included: org.codehaus.mojo.natives:maven-native-generic-c:jar:1.0-alpha-3
[DEBUG] Included: org.codehaus.mojo.natives:maven-native-msvc:jar:1.0-alpha-3
[DEBUG] Included: org.codehaus.mojo.natives:maven-native-bcc:jar:1.0-alpha-3
[DEBUG] Included: org.codehaus.mojo.natives:maven-native-manager:jar:1.0-alpha-3
[DEBUG] Extension realms for project de.maeyer:native-linux:so:0.0.1-SNAPSHOT: [ClassRealm[extension>org.codehaus.mojo:native-maven-plugin:1.0-alpha-3, parent: ClassRealm[plexus.core, parent: null]]]
[DEBUG] Created new class realm project>de.maeyer:native-linux:0.0.1-SNAPSHOT
[DEBUG] Populating project realm for de.maeyer:native-linux:so:0.0.1-SNAPSHOT
[DEBUG] === REACTOR BUILD PLAN ================================================
[DEBUG] Project: de.maeyer:native-linux:so:0.0.1-SNAPSHOT
[DEBUG] Tasks: [org.codehaus.mojo:native-maven-plugin:1.0-alpha-3:javah]
[DEBUG] Style: Regular
[DEBUG] =======================================================================
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - de.maeyer:native-linux:so:0.0.1-SNAPSHOT 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[DEBUG] === PROJECT BUILD PLAN ================================================
[DEBUG] Project: de.maeyer:native-linux:0.0.1-SNAPSHOT
[DEBUG] Dependencies (collect): []
[DEBUG] Dependencies (resolve): [compile]
[DEBUG] -----------------------------------------------------------------------
[DEBUG] Goal: org.codehaus.mojo:native-maven-plugin:1.0-alpha-3:javah (default-cli)
[DEBUG] Style: Regular
[DEBUG] Configuration: <?xml version="1.0" encoding="UTF-8"?>
<configuration>
<implementation default-value="default"/>
<outputDirectory default-value="$
{project.build.directory}
/native/javah"/>
<project>$
{project}
</project>
<verbose default-value="false"/>
<workingDirectory default-value="$
{basedir}
">$
{workingDirectory}
</workingDirectory>
</configuration>
[DEBUG] =======================================================================
[INFO]
[INFO] — native-maven-plugin:1.0-alpha-3:javah (default-cli) @ native-linux —
[DEBUG] Created new class realm plugin>org.codehaus.mojo:native-maven-plugin:1.0-alpha-3
[DEBUG] Populating plugin realm for org.codehaus.mojo:native-maven-plugin:1.0-alpha-3
[DEBUG] Included: org.codehaus.mojo:native-maven-plugin:maven-plugin:1.0-alpha-3
[DEBUG] Excluded: org.apache.maven:maven-project:jar:2.0.6
[DEBUG] Excluded: org.apache.maven:maven-settings:jar:2.0.6
[DEBUG] Excluded: org.apache.maven:maven-model:jar:2.0.6
[DEBUG] Included: org.codehaus.plexus:plexus-utils:jar:1.5.6
[DEBUG] Excluded: org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9
[DEBUG] Excluded: classworlds:classworlds:jar:1.1-alpha-2
[DEBUG] Excluded: org.apache.maven:maven-profile:jar:2.0.6
[DEBUG] Excluded: org.apache.maven:maven-artifact-manager:jar:2.0.6
[DEBUG] Excluded: org.apache.maven:maven-repository-metadata:jar:2.0.6
[DEBUG] Excluded: org.apache.maven:maven-artifact:jar:2.0.6
[DEBUG] Excluded: org.apache.maven.wagon:wagon-provider-api:jar:1.0-beta-2
[DEBUG] Excluded: org.apache.maven:maven-plugin-registry:jar:2.0.6
[DEBUG] Excluded: org.apache.maven:maven-plugin-api:jar:2.0.6
[DEBUG] Included: bcel:bcel:jar:5.1
[DEBUG] Included: org.codehaus.mojo.natives:maven-native-api:jar:1.0-alpha-3
[DEBUG] Included: org.codehaus.mojo.natives:maven-native-javah:jar:1.0-alpha-3
[DEBUG] Included: commons-lang:commons-lang:jar:2.4
[DEBUG] Included: org.codehaus.mojo.natives:maven-native-generic-c:jar:1.0-alpha-3
[DEBUG] Included: org.codehaus.mojo.natives:maven-native-msvc:jar:1.0-alpha-3
[DEBUG] Included: org.codehaus.mojo.natives:maven-native-bcc:jar:1.0-alpha-3
[DEBUG] Included: org.codehaus.mojo.natives:maven-native-manager:jar:1.0-alpha-3
[DEBUG] Configuring mojo 'org.codehaus.mojo:native-maven-plugin:1.0-alpha-3:javah' with basic configurator -->
[DEBUG] (f) implementation = default
[DEBUG] (f) outputDirectory = /home/peter/workspace2/project/native/linux/target/native/javah
[DEBUG] (f) project = MavenProject: de.maeyer:native-linux:0.0.1-SNAPSHOT @ /home/peter/workspace2/project/native/linux/pom.xml
[DEBUG] (f) verbose = false
[DEBUG] (f) workingDirectory = /home/peter/workspace2/project/native/linux
[DEBUG] – end configuration –
[INFO] Parsing /home/peter/workspace2/project/java/target/classes for native classes.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.225s
[INFO] Finished at: Wed Dec 02 21:06:48 CET 2009
[INFO] Final Memory: 4M/54M
[INFO] ------------------------------------------------------------------------
[ERROR] Error searching for native class in /home/peter/workspace2/project/java/target/classes: error in opening zip file -> [Help 1]
org.apache.maven.plugin.MojoExecutionException: Error searching for native class in /home/peter/workspace2/project/java/target/classes
at org.codehaus.mojo.natives.plugin.NativeJavahMojo.getNativeClassNames(NativeJavahMojo.java:292)
at org.codehaus.mojo.natives.plugin.NativeJavahMojo.createProviderConfiguration(NativeJavahMojo.java:308)
at org.codehaus.mojo.natives.plugin.NativeJavahMojo.execute(NativeJavahMojo.java:144)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:105)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:547)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:317)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:239)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:102)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:421)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:156)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:121)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: java.util.zip.ZipException: error in opening zip file
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:131)
at java.util.zip.ZipFile.<init>(ZipFile.java:148)
at org.codehaus.mojo.natives.plugin.NativeJavahMojo.getNativeClassNames(NativeJavahMojo.java:262)
... 18 more
[ERROR]
[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/MojoExecutionException
Indeed the plugin expects a zip file. However, M2Eclipse does workspace artifact resolution, which means it can also be a directory with class files. I've created and attached a "patch" (well, sort of, since it's not in the actual patch format). It's just one file, the fix should be obvious.
Thanks to this patch, the "javah" goal now also works with M2Eclipse workspace artifact resolution!