Classpath empty when adding to p

2019-06-24 00:16发布

问题:

I am using this simple pom.xml to generate an OSGi-bundle using the maven-bundle-plugin:

<project xmlns="http://maven.apache.org/POM/4.0.0" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
                             http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>de.test.osgi</groupId>
    <artifactId>test</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>bundle</packaging>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>2.3.7</version>
                <extensions>true</extensions>
            </plugin>
        </plugins>
    </build>
</project>

This works as expected (that project contains a single public class that I have verified to be exported in the bundle). Now , if I add the following <configuration> to the plugin:

<configuration>
    <outputDirectory>D:\Test</outputDirectory>
</configuration>

the build fails with the following error:

[INFO] --- maven-bundle-plugin:2.3.7:bundle (default-cli) @ test ---
[WARNING] Bundle de.test.osgi:test:bundle:0.0.1-SNAPSHOT : Classpath is empty. Private-Package and Export-Package can only expand from the classpath when there is one
[WARNING] Bundle de.test.osgi:test:bundle:0.0.1-SNAPSHOT : Instructions in Private-Package, or -testpackages that are never used: .*
Classpath: 
[ERROR] Bundle de.test.osgi:test:bundle:0.0.1-SNAPSHOT : The JAR is empty: dot
[ERROR] Error(s) found in bundle configuration
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.891s
[INFO] Finished at: Fri Mar 30 14:49:46 CEST 2012
[INFO] Final Memory: 8M/20M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.felix:maven-bundle-plugin:2.3.7:bundle (default-cli) on project test: Error(s) found in bundle configuration -> [Help 1]

Why is the classpath empty? What does the <outputDirectory> have to do with it? Is this a bug, or have I misunderstood something?

Edit Running with debug-output reveals that the classpath is indeed identical with <outputDirectory>. By default, this is mavens target directory, so he will find the classes to include in the bundle there. If I change it, it will point to a directory that contains no classes to include. Confusingly, the documentation for the plugin says that <outputDirectory> is:

The directory for the generated bundles.

Is this a mistake?

回答1:

outputDirectory is where the compiled classes have been written too - the error regarding empty classpath "dot" is due to giving maven-bundle-plugin an empty directory.

The bundle plugin writes the MANIFEST.MF to the outputDirectory location and this is also where it expects to find any other metadata (e.g. scr plugin's output) for the bundle.

Are you using the compiler plugin? If not it looks like a bug in the bundle plugin not honouring the outputDirectory when it calls the compiler (but honouring it everywhere else).

As @nobeh points out, you should be fine if ${project.build.outputDirectory} and outputDirectory point to the same location.



回答2:

First i would suggest to check your bundle configuration and furthermore i would never use absolute path in particular platform dependent paths like D:\ etc. On the other hand the default in Maven is the target folder to put created output. Based on the docs there must be more configuration.



回答3:

It's a wild guess, but try either D:/Test or D:\\Test.