Mojo
  1. Mojo
  2. MOJO-1468

Executing native:javah goal results in "error in opening zip file"

    Details

    • Type: Bug Bug
    • Status: Open Open
    • Priority: Critical Critical
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: native
    • Labels:
      None
    • Environment:
    • Complexity:
      Intermediate
    • Number of attachments :
      2

      Description

      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

      1. MOJO-1468.patch
        5 kB
        Peter De Maeyer
      2. project.tar.gz
        6 kB
        Peter De Maeyer

        Issue Links

          Activity

          Hide
          Peter De Maeyer added a comment -

          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!

          Show
          Peter De Maeyer added a comment - 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!
          Hide
          Peter De Maeyer added a comment -

          A proposed patch.

          Show
          Peter De Maeyer added a comment - A proposed patch.
          Hide
          Peter De Maeyer added a comment -

          Looking further into the issue, I am beginning to understand better what is goign on. My earlier patch was a bit too short-sighted. Although it does fix the immediate symptom, it does not fix the root cause. Since I explicitly define the native class name in the configuration, it should not even have to scan for native classes. It only does that in case the native class name is not configured.

          So... the question I should be asking is: why aren't any of the fields in NativeJavahMojo filled in, even though I've configured the corresponding values in the pom.xml? Does M2Eclipse somehow break the configuration of NativeJavahMojo, forcing it to fall back to defaults?

          I don't have the answers (yet), but I really need the native plugin to work so I'll keep looking...

          Show
          Peter De Maeyer added a comment - Looking further into the issue, I am beginning to understand better what is goign on. My earlier patch was a bit too short-sighted. Although it does fix the immediate symptom, it does not fix the root cause. Since I explicitly define the native class name in the configuration, it should not even have to scan for native classes. It only does that in case the native class name is not configured. So... the question I should be asking is: why aren't any of the fields in NativeJavahMojo filled in, even though I've configured the corresponding values in the pom.xml? Does M2Eclipse somehow break the configuration of NativeJavahMojo, forcing it to fall back to defaults? I don't have the answers (yet), but I really need the native plugin to work so I'll keep looking...
          Hide
          Peter De Maeyer added a comment -

          Hmm, root cause found:

          http://old.nabble.com/m2eclipse-does-not-configure-mojo-from-pom.xml-td22940611.html#a26647243

          So in fact there are 2 issues:

          • M2Eclipse does not always correctly pass on the configuration to the mojos (TODO ref. to M2Eclipse bug?)
          • When scanning the classpath, NativeJavahMojo assumes that artifacts of type "jar" are always jars (seems reasonable . However, with M2Eclipse workspace resolution enabled, artifacts of type "jar" can also be "real" directories containing class files. For this I have created a patch. It is likely that other mojos require a similar fix in order to work correctly under M2Eclipse... In fact, it may even be preferrable that it is the responsibility of M2Eclipse to "decorate" a real class folder with a "virtual" jar API, so that none of the mojos and plugins need to be adjusted.
          Show
          Peter De Maeyer added a comment - Hmm, root cause found: http://old.nabble.com/m2eclipse-does-not-configure-mojo-from-pom.xml-td22940611.html#a26647243 So in fact there are 2 issues: M2Eclipse does not always correctly pass on the configuration to the mojos (TODO ref. to M2Eclipse bug?) When scanning the classpath, NativeJavahMojo assumes that artifacts of type "jar" are always jars (seems reasonable . However, with M2Eclipse workspace resolution enabled, artifacts of type "jar" can also be "real" directories containing class files. For this I have created a patch. It is likely that other mojos require a similar fix in order to work correctly under M2Eclipse... In fact, it may even be preferrable that it is the responsibility of M2Eclipse to "decorate" a real class folder with a "virtual" jar API, so that none of the mojos and plugins need to be adjusted.
          Hide
          Dan Tran added a comment -

          would accepting .zip dependency in addition to .jar work?

          Show
          Dan Tran added a comment - would accepting .zip dependency in addition to .jar work?
          Hide
          Peter De Maeyer added a comment -

          No that would not help. The only thing that would help is adding support for a directory structure containing .class files.
          In fact, the artifact of type "jar" should be interpreted as "anything that is a valid element on the classpath". Valid classpath elements are
          1) .jar files (or .zip files, since a .jar file is basically a .zip file)
          2) a directory structure containing .class files

          Show
          Peter De Maeyer added a comment - No that would not help. The only thing that would help is adding support for a directory structure containing .class files. In fact, the artifact of type "jar" should be interpreted as "anything that is a valid element on the classpath". Valid classpath elements are 1) .jar files (or .zip files, since a .jar file is basically a .zip file) 2) a directory structure containing .class files
          Hide
          Dan Tran added a comment -

          on point #2, we are already taking target/classes ( or similar ) into account

          I am not sure why having javah goal to accept .zip extension would not work

          Show
          Dan Tran added a comment - on point #2, we are already taking target/classes ( or similar ) into account I am not sure why having javah goal to accept .zip extension would not work
          Hide
          Dan Tran added a comment -

          latest kepler does not have this issue any more. I setup native-maven-plugin/src/it to be m2e aware. It looks happy

          Show
          Dan Tran added a comment - latest kepler does not have this issue any more. I setup native-maven-plugin/src/it to be m2e aware. It looks happy

            People

            • Assignee:
              Unassigned
              Reporter:
              Peter De Maeyer
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: