Uploaded image for project: 'Felix'
  1. Felix
  2. FELIX-660

"Class in different directory than declared" error when bundle classes in a directory other than bundle root

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: maven-bundle-plugin-1.4.0, maven-bundle-plugin-1.4.1
    • Fix Version/s: maven-bundle-plugin-2.0.0
    • Component/s: Maven Bundle Plugin
    • Labels:
      None
    • Environment:
      Maven version: 2.0.9
      Java version: 1.6.0_04
      OS name: "windows xp" version: "5.1" arch: "x86" Family: "windows"

      Description

      Per the message http://www.mail-archive.com/users@felix.apache.org/msg01814.html in Felix mailing list,

      When classes are not in a subdirectory under bundle root bundle:bundle fail with the error like:

      [INFO] [bundle:bundle]
      [ERROR] Error building bundle test:test:bundle:0.0.1-SNAPSHOT : Class in different directory than declared. Path from class name is test/Test.class but the path in the jar is /test/Test.class from Jar:dot
      [ERROR] Error building bundle test:test:bundle:0.0.1-SNAPSHOT : Class in different directory than declared. Path from class name is test/Test.class but the path in the jar is /test/Test.class from Jar:dot
      [ERROR] Error(s) found in bundle configuration
      [ERROR]

      My maven-bundle-plugin configuration is :

      <plugins>
      <plugin>
      <groupId>org.apache.felix</groupId>
      <artifactId>maven-bundle-plugin</artifactId>
      <extensions>true</extensions>
      <configuration>
      <instructions>
      <Include-Resource>

      {maven-resources}

      ,classes=target/classes</Include-Resource>
      <Implementation-Title>Test</Implementation-Title>
      <Implementation-Version>$

      {pom.version}

      </Implementation-Version>
      <Implementation-Vendor>XXX</Implementation-Vendor>
      <Implementation-Vendor-Id>XXX</Implementation-Vendor-Id>
      <Private-Package>test*</Private-Package>
      <Bundle-ClassPath>classes</Bundle-ClassPath>
      </instructions>
      </configuration>
      </plugin>
      </plugins>

      A simple test project is attached. Run "mvn install" to recreate the problem.

      1. FELIX-660-20090129.patch
        0.7 kB
        Stuart McCulloch
      2. FELIX-660-BND-PATCH.txt
        1 kB
        Stuart McCulloch
      3. test_felix_660.zip
        3 kB
        Gopalakrishnan U

        Activity

        Hide
        ugopalak@in.ibm.com Gopalakrishnan U added a comment -

        A simple test eclipse project to recreate the problem. Unzip/Import the project into eclipse and run "mvn install' to recreate the problem.

        Show
        ugopalak@in.ibm.com Gopalakrishnan U added a comment - A simple test eclipse project to recreate the problem. Unzip/Import the project into eclipse and run "mvn install' to recreate the problem.
        Hide
        ncampion Nick Campion added a comment -

        Verified on linux (SLES 10 2.6.16.60), arch "x86", java version java 1.5.0 SR7

        Show
        ncampion Nick Campion added a comment - Verified on linux (SLES 10 2.6.16.60), arch "x86", java version java 1.5.0 SR7
        Hide
        mcculls Stuart McCulloch added a comment -

        Thanks for the testcase - setting fix target to 1.4.3 because this will require a change to the Bnd library, specifically the analyzeJar method in Processor.java:127 where it removes the prefix from the path, but doesn't check for leftover slashes at the beginning. This causes the failing check, because the relative path still has a slash at the beginning but the path computed from the class doesn't.

        Show
        mcculls Stuart McCulloch added a comment - Thanks for the testcase - setting fix target to 1.4.3 because this will require a change to the Bnd library, specifically the analyzeJar method in Processor.java:127 where it removes the prefix from the path, but doesn't check for leftover slashes at the beginning. This causes the failing check, because the relative path still has a slash at the beginning but the path computed from the class doesn't.
        Hide
        topping Brian Topping added a comment - - edited

        For some reason, adding

        <Include-Resource>src/main/resources</Include-Resource>

        avoids this problem.

        Show
        topping Brian Topping added a comment - - edited For some reason, adding <Include-Resource>src/main/resources</Include-Resource> avoids this problem.
        Hide
        mcculls Stuart McCulloch added a comment -

        The following patch to Bnd 0.0.295 fixes two problems:

        1) path entries on the Bundle-ClassPath won't end in '/', but analyzeJar expects the given path prefix to end in '/' - so we need to either add it before analyzeJar (as done in this patch) or make analyzeJar more forgiving of path prefixes that don't end in '/'

        2) the Verifier class has a bug where embedded directories always cause a NPE because there is no embedded resource (possible copy-paste error as the TODO comment suggests this is not finished, so have just removed that line for now)

        Show
        mcculls Stuart McCulloch added a comment - The following patch to Bnd 0.0.295 fixes two problems: 1) path entries on the Bundle-ClassPath won't end in '/', but analyzeJar expects the given path prefix to end in '/' - so we need to either add it before analyzeJar (as done in this patch) or make analyzeJar more forgiving of path prefixes that don't end in '/' 2) the Verifier class has a bug where embedded directories always cause a NPE because there is no embedded resource (possible copy-paste error as the TODO comment suggests this is not finished, so have just removed that line for now)
        Hide
        mcculls Stuart McCulloch added a comment -

        Hi Peter, please see attached patch for Bnd 0.0.295

        Show
        mcculls Stuart McCulloch added a comment - Hi Peter, please see attached patch for Bnd 0.0.295
        Hide
        mcculls Stuart McCulloch added a comment -

        Updated patch based on Bnd 0.0.308

        Show
        mcculls Stuart McCulloch added a comment - Updated patch based on Bnd 0.0.308
        Hide
        pkriens Peter Kriens added a comment -

        Applied the patch in bnd-310

        Show
        pkriens Peter Kriens added a comment - Applied the patch in bnd-310
        Hide
        mcculls Stuart McCulloch added a comment -

        Closing as maven-bundle-plugin 2.0.0 has been released.

        Show
        mcculls Stuart McCulloch added a comment - Closing as maven-bundle-plugin 2.0.0 has been released.

          People

          • Assignee:
            pkriens Peter Kriens
            Reporter:
            ugopalak@in.ibm.com Gopalakrishnan U
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development