您必须将 jars 作为依赖项添加到 pom.xml 中,然后在<build>标记中为 maven-bundle-plugin 使用以下公式:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<manifestLocation>META-INF</manifestLocation>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Version>${project.version}</Bundle-Version>
<Export-Package>*</Export-Package>
<Bundle-Activator>your.activator.package.Activator</Bundle-Activator>
<Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
<Embed-Directory>target/dependency</Embed-Directory>
<Embed-StripGroup>true</Embed-StripGroup>
<Embed-Transitive>true</Embed-Transitive>
</instructions>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
</plugin>
还要添加以下内容以使一切都与 m2e 一起工作:
请参阅:m2e 不支持 maven-dependency-plugin(目标“copy-dependencies”、“unpack”)
<pluginManagement>
<plugins>
<!-- Ignore/Execute plugin execution -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<!-- copy-dependency plugin -->
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<versionRange>[1.0.0,)</versionRange>
<goals>
<goal>copy-dependencies</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
还要添加以下内容以使其与 Eclipse PDE 一起使用(取自Apache Felix 网站):
<profiles>
<profile>
<activation>
<property>
<name>m2e.version</name>
</property>
</activation>
<properties>
<osgi-version-qualifier>qualifier</osgi-version-qualifier>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<!-- PDE does not honour custom manifest location -->
<manifestLocation>META-INF</manifestLocation>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>