问题
I am very confused by the felix-bundle plugin. The documentation says of the Import-Package tag
This header rarely has to be explicitly specified. However, in certain cases when there is an unwanted import, such an import can be removed by using a negation package pattern
But I am building a plugin and it seems to be importing lots of things that I don't want. javax.servlet is going in, as are junit.* and org.junit.*, and org.testng, and some apache logging packages. All of these are making my package crash in use with a missing requirement error.
The thing is, I have no idea why these are getting included in the first place. Very confused. Help welcome.
In response to an answer, AFAIK, I am not using javax.servlet anywhere in my code. My POM currently looks like this. I've had to exclude lots of packages which are otherwise breaking the load.
All turning out to be a bit of a nightmare!
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>7</version>
</parent>
<groupId>uk.org.russet</groupId>
<artifactId>uk.org.russet.protege.nrepl-clojure</artifactId>
<version>0.1.0-SNAPSHOT</version>
<name>protege-nrepl</name>
<description>Provide an NREPL client to use Clojure inside Protege</description>
<packaging>bundle</packaging>
<dependencies>
<dependency>
<groupId>uk.org.russet</groupId>
<artifactId>nrepl-clojure</artifactId>
<version>1.0.0</version>
</dependency>
<!--dependency>
<groupId>edu.stanford.protege</groupId>
<artifactId>org.protege.common</artifactId>
<version>5.0.0-beta-05-SNAPSHOT</version>
<scope>provided</scope>
</dependency-->
<dependency>
<groupId>edu.stanford.protege</groupId>
<artifactId>org.protege.editor.core.application</artifactId>
<version>5.0.0-beta-05-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>edu.stanford.protege</groupId>
<artifactId>org.protege.editor.owl</artifactId>
<version>5.0.0-beta-05-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-ClassPath>.</Bundle-ClassPath>
<Bundle-SymbolicName>${project.artifactId};singleton:=true</Bundle-SymbolicName>
<Bundle-Vendor>The Protege Development Team</Bundle-Vendor>
<Import-Package>
!javax.servlet*,!junit.*,!org.junit*,!org.apache.*,
!org.testng.*,!sun.misc.*,org.protege.editor.*,
org.protege.editor.core,org.protege.editor.core.ui.workspace,
org.protege.editor.owl.model,org.protege.editor.core.editorkit,
org.semanticweb.owlapi.model, *
</Import-Package>
<Include-Resource>plugin.xml, {maven-resources}</Include-Resource>
<Embed-Transitive>true</Embed-Transitive>
<Embed-Dependency>*;scope=compile</Embed-Dependency>
</instructions>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>install</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
</executions>
</configuration>
</plugin>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<pde>true</pde>
</configuration>
</plugin>
</plugins>
</build>
</project>
回答1:
The dependencies are added because some code inside your bundle uses those packages. For example if any of your code uses javax.servlet then the bundle will necessarily import javax.servlet. So this import at least seems reasonable.
The imports of testing libraries do not seem so reasonable, of course. It suggests that your tests have been included in your bundle alongside the "real" classes, which should not happen. Do you keep your tests in the same source folder as the real classes? It's normal and recommended practice to write test code in a separate source folder; in Maven this is usually src/test/java.
If that's not the case then you should show the configuration you have used.
来源:https://stackoverflow.com/questions/20679114/felix-bundle-has-lots-of-wrong-imports