1 year ago

#12076

test-img

1288Meow

ClassNotFoundException for Project Dependency Maven or karaf-maven-plugin Exception

I have a multimodule project with Project A being a dependency of Project B.

When I run a Junit test for Project B, Project A classes are successfully imported and methods called. However, when I run mvn clean install for Project B, ClassNotFoundException is thrown for karaf-maven-plugin for the Activator.class of Project B.

Failed to execute goal org.apache.karaf.tooling:karaf-maven-plugin:4.3.3:run (run) on project org.project.b: Can't start container: Can't deploy project artifact in container: Activator start error in bundle org.project.b [55]. org/project.a/core/Engine: org.project.a.Engine not found by org.project.b[55] -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.karaf.tooling:karaf-maven-plugin:4.3.3:run (run) on project org.project.b: Can't start container ... Caused by: java.lang.ClassNotFoundException: org.project.a.Engine not found by org.project.b [55] at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1565) at org.apache.felix.framework.BundleWiringImpl.access$300(BundleWiringImpl.java:78) at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1950) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521) ... 30 more

The pom.xml for Project looks like this:

<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>

Code for Project B Activator Class

import org.osgi.framework.BundleActivator;

import org.osgi.framework.BundleContext; import org.project.a.Engine;

public class Activator implements 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
}

java

maven

osgi

apache-karaf

karaf-maven-plugin

0 Answers

Your Answer

Accepted video resources