我有一个多模块项目,项目 A 是项目 B 的依赖项。
当我为项目 B 运行 Junit 测试时,项目 A 类已成功导入并调用了方法。但是,当我为项目 B 运行 mvn clean install 时,会为项目 B 的 Activator.class 的 karaf-maven-plugin 引发 ClassNotFoundException。
无法在项目 org.project.b 上执行目标 org.apache.karaf.tooling:karaf-maven-plugin:4.3.3:run (run):无法启动容器:无法在容器中部署项目工件:激活器包 org.project.b [55] 中的启动错误。org/project.a/core/Engine: org.project.b[55] 找不到 org.project.a.Engine -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: 未能执行目标 org. apache.karaf.tooling:karaf-maven-plugin:4.3.3:run (run) on project org.project.b: Can't start container ... 引起:java.lang.ClassNotFoundException: org.project.a .Engine 在 org.apache.felix.framework.BundleWiringImpl.access$300(BundleWiringImpl.java: 78)在 org.apache.felix.framework。
Project 的 pom.xml 如下所示:
<dependency>
<groupId>org.project</groupId>
<artifactId>org.project.a</artifactId>
<version>4.0.0-SNAPSHOT</version>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>${maven-bundle-plugin.version}</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Version>${project.version}</Bundle-Version>
<Import-Package>*;resolution:=optional</Import-Package>
<Export-Package>!${bundle.namespace}.*</Export-Package>
<Private-Package>${bundle.namespace}.*</Private-Package>
<Bundle-Activator>${bundle.namespace}.Activator</Bundle-Activator>
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>karaf-maven-plugin</artifactId>
<version>${karaf.version}</version>
<executions>
<execution>
<id>run</id>
<phase>integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<karafDistribution>mvn:org.apache.karaf/apache-karaf/${karaf.version}/zip</karafDistribution>
<keepRunning>true</keepRunning>
<deployProjectArtifact>true</deployProjectArtifact>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
项目 B 激活器类的代码
import org.osgi.framework.BundleActivator;
导入 org.osgi.framework.BundleContext;导入 org.project.a.Engine;
公共类 Activator 实现 BundleActivator {
@Override
public void start(BundleContext bundleContext) {
System.out.println("Project B Bundle Running Successfully !!!!");
org.project.a.Engine.printHello();
System.out.println("Testing testing !!!!");
}
@Override
public void stop(BundleContext bundleContext) {
// nothing to do
}