Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
223 views
in Technique[技术] by (71.8m points)

java - NoClassDefFoundError in OSGi although it is exported and imported

I tried to create a basic virtual reality IDE based on Karaf.

I have 3 maven-projects:

  1. VRServer who connect to a native-component for rendering.
  2. VR Component Toolkit for VR-HMI-Widgets (Having a VRFrame who extends from VRComponent) as a Multi-Module-Maven-Project.
  3. The VR IDE project read/write files and execute lowlevel commands.

enter image description here

I installed all of them into Karaf:

karaf@root()> bundle:list
START LEVEL 100 , List Threshold: 50
 ID | State  | Lvl | Version            | Name
----+--------+-----+--------------------+---------------------------------------------------------------------------
 31 | Active |  80 | 4.3.0              | Apache Karaf :: OSGi Services :: Event
 54 | Active |  80 | 1.3.2              | Apache Aries SPI Fly Dynamic Weaving Bundle
 55 | Active |  80 | 9.0.0              | org.objectweb.asm
 56 | Active |  80 | 9.0.0              | org.objectweb.asm.commons
 57 | Active |  80 | 9.0.0              | org.objectweb.asm.tree
 58 | Active |  80 | 9.0.0              | org.objectweb.asm.tree.analysis
 59 | Active |  80 | 9.0.0              | org.objectweb.asm.util
 60 | Active |  80 | 2.0.17             | OpenWebBeans Core
 61 | Active |  80 | 2.0.17             | SPI definition
 62 | Active |  80 | 1.1.3              | Apache Aries CDI - CDI Component Runtime (CCR)
 63 | Active |  80 | 1.1.3              | Apache Aries CDI - SPI classes for Portable Extensions
 64 | Active |  80 | 1.1.3              | Apache Aries CDI - Container using Apache OpenWebBeans
 65 | Active |  80 | 1.1.3              | Apache Aries CDI - SPI
 66 | Active |  80 | 1.0.12             | Apache Felix Converter
 67 | Active |  80 | 1.2.0              | Apache Geronimo JSR-330 Spec 1.0
 68 | Active |  80 | 1.1.0              | Apache Geronimo Expression Language Spec 2.2
 69 | Active |  80 | 1.2.0              | Apache Geronimo Interceptor Spec 1.2
 70 | Active |  80 | 1.2.0              | Apache Geronimo JCDI Spec 2.0
 71 | Active |  80 | 1.3.0.3            | Apache ServiceMix :: Specs :: Annotation API 1.3
 72 | Active |  80 | 4.17.0             | Apache XBean :: ASM shaded (repackaged)
 73 | Active |  80 | 4.17.0             | Apache XBean OSGI Bundle Utilities
 74 | Active |  80 | 4.17.0             | Apache XBean :: Finder shaded (repackaged)
 75 | Active |  80 | 1.0.1.201505202024 | org.osgi:org.osgi.namespace.extender
 76 | Active |  80 | 1.0.0.201505202024 | org.osgi:org.osgi.namespace.implementation
 77 | Active |  80 | 1.0.0.201505202024 | org.osgi:org.osgi.namespace.service
 78 | Active |  80 | 1.0.0.201810101357 | org.osgi:org.osgi.service.cdi
 79 | Active |  80 | 1.1.0.201802012106 | org.osgi:org.osgi.util.function
 80 | Active |  80 | 1.1.0.201802012106 | org.osgi:org.osgi.util.promise
 81 | Active |  80 | 4.3.1.SNAPSHOT     | Apache Karaf :: OSGi Services :: Event
134 | Active |  80 | 1.0.0              | Virtual reality server
135 | Active |  80 | 0.0.1.SNAPSHOT     | VRComponent
136 | Active |  80 | 0.0.1.SNAPSHOT     | VRFrame
142 | Active |  80 | 0.0.1.SNAPSHOT     | Virtual reality integrated development environment (VRIDE)
karaf@root()>

But when I tried to start the VRIDE bundle, I get this exception:

10:00:42.193 WARN [fileinstall-C:Program Filesapache-karaf-4.3.0/deploy] Error while creating extension
java.lang.NoClassDefFoundError: Lde/e_nexus/vr/tk/VRFrame;
        at java.lang.Class.getDeclaredFields0(Native Method) ~[?:1.8.0_232]
        at java.lang.Class.privateGetDeclaredFields(Class.java:2611) ~[?:1.8.0_232]
        at java.lang.Class.getDeclaredFields(Class.java:1944) ~[?:1.8.0_232]
        at org.apache.aries.cdi.container.internal.util.Reflection.allFields(Reflection.java:47) ~[!/:1.1.3]
        at org.apache.aries.cdi.container.internal.annotated.AnnotatedTypeImpl.<init>(AnnotatedTypeImpl.java:42) ~[!/:1.1.3]
        at org.apache.aries.cdi.container.internal.container.Discovery.lambda$discover$8(Discovery.java:133) ~[!/:1.1.3]
        at java.util.HashMap$Values.forEach(HashMap.java:981) ~[?:1.8.0_232]

This is the Java-Class I tried to load:

package de.e_nexus.desktop.vr.ide;

import java.util.logging.Logger;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;

import org.osgi.service.cdi.annotations.Reference;
import org.osgi.service.cdi.annotations.Service;

import de.e_nexus.vr.server.ClientKeyboardScancode;
import de.e_nexus.vr.server.VRClientHelmetAndControllerListener;
import de.e_nexus.vr.server.VRClientKeyboardListener;
import de.e_nexus.vr.server.VRServer;
import de.e_nexus.vr.server.listeners.VRClientRequestAppInfo;
import de.e_nexus.vr.server.listeners.VRClientStatusListener;
import de.e_nexus.vr.server.listeners.interaction.HelmetAndControllerInfo;
import de.e_nexus.vr.server.osgi.inter.VRServerService;
import de.e_nexus.vr.tk.VRFrame;

@ApplicationScoped
@Service
public class StartIDE implements VRClientStatusListener, VRClientRequestAppInfo, VRClientHelmetAndControllerListener, VRClientKeyboardListener {
    /**
     * The logger for this class.
     */
    private static final Logger LOG = Logger.getLogger(StartIDE.class.getCanonicalName());

    private final static Object lock = new Object();

    private VRServer vrServer;

    public void notifyStatus(boolean connected) {
        if (!connected) {
            synchronized (lock) {
                lock.notify();
            }
        }
    }

    @Reference
    @Inject
    private VRServerService vrServerService;

    private VRFrame applicationFrame;

    @PostConstruct
    public void initialize() {
        LOG.fine("Starting VR IDE");
        vrServer = vrServerService.getVRServer();
        applicationFrame = new VRFrame(vrServer, "test");

        LOG.info(getLatin1Title() + " started successfully!");
    }

    @PreDestroy
    public void teardown() {
        applicationFrame.remove();
        LOG.info("Stoped " + getLatin1Title() + " successfully!");
        vrServer = null;
    }

    public VRServer getVrServer() {
        return vrServer;
    }

    @Override
    public void notify(HelmetAndControllerInfo haci) {

    }

    @Override
    public String getLatin1Title() {
        return "VR IDE";
    }

    @Override
    public void notifyKeyboardEvent(ClientKeyboardScancode[] downs, ClientKeyboardScancode[] ups, long incommingTime) {
        System.out.println("me");
    }
}

VRServer-Codebase

VRToolkit-Codebase

VRIDE-Codebase


EDIT:

Here is the complete stacktrace:

java.lang.NoClassDefFoundError: Lde/e_nexus/vr/tk/VRFrame;
        at java.lang.Class.getDeclaredFields0(Native Method) ~[?:1.8.0_232]
        at java.lang.Class.privateGetDeclaredFields(Class.java:2611) ~[?:1.8.0_232]
        at java.lang.Class.getDeclaredFields(Class.java:1944) ~[?:1.8.0_232]
        at org.apache.aries.cdi.container.internal.util.Reflection.allFields(Reflection.java:47) ~[!/:1.1.3]
        at org.apache.aries.cdi.container.internal.annotated.AnnotatedTypeImpl.<init>(AnnotatedTypeImpl.java:42) ~[!/:1.1.3]
        at org.apache.aries.cdi.container.internal.container.Discovery.lambda$discover$8(Discovery.java:133) ~[!/:1.1.3]
        at java.util.HashMap$Values.forEach(HashMap.java:981) ~[?:1.8.0_232]
        at org.apache.aries.cdi.container.internal.container.Discovery.discover(Discovery.java:130) ~[!/:1.1.3]
        at org.apache.aries.cdi.container.internal.container.ContainerState.<init>(ContainerState.java:178) ~[!/:1.1.3]
        at org.apache.aries.cdi.container.internal.Activator.doCreateExtension(Activator.java:209) [!/:1.1.3]
        at org.apache.felix.utils.extender.AbstractExtender.createExtension(AbstractExtender.java:242) [!/:1.1.3]
        at org.apache.felix.utils.extender.AbstractExtender.modifiedBundle(AbstractExtender.java:227) [!/:1.1.3]
        at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:488) [osgi.core-7.0.0.jar:?]
        at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:420) [osgi.core-7.0.0.jar:?]
        at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:232) [osgi.core-7.0.0.jar:?]
        at org.osgi.util.tracker.BundleTracker$Tracked.bundleChanged(BundleTracker.java:450) [osgi.core-7.0.0.jar:?]
        at org.apache.felix.framework.EventDispatcher.invokeBundleListenerCallback(EventDispatcher.java:915) [org.apache.felix.framework-6.0.3.jar:?]
        at org.apache.felix.framework.EventDispatcher.fireEventImmediately(EventDispatcher.java:834) [org.apache.felix.framework-6.0.3.jar:?]
        at org.apache.felix.framework.EventDispatcher.fireBundleEvent(EventDispatcher.java:516) [org.apache.felix.framework-6.0.3.jar:?]
        at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4817) [org.apache.felix.framework-6.0.3.jar:?]
        at org.apache.felix.framework.Felix.startBundle(Felix.java:2336) [org.apache.felix.framework-6.0.3.jar:?]
        at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:998) [org.apache.felix.framework-6.0.3.jar:?]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1260) [!/:3.6.8]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1233) [!/:3.6.8]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:520) [!/:3.6.8]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:365) [!/:3.6.8]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:316) [!/:3.6.8]
Caused by: java.lang.ClassNotFoundException: de.e_nexus.vr.tk.VRFrame not found by de.e-nexus.component [87]
        at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1597) ~[?:?]
        at org.apache.felix.framework.BundleWiringImpl.access$300(BundleWiringImpl.java:79) ~[?:?]
        at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1982) ~[?:?]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:351) ~[?:1.8.0_232]
        at org.apache.felix.framework.BundleWiringImpl.getClassByDelegation(BundleWiringImpl.java:1375) ~[?:?]
        at org.apache.felix.framework.BundleWiringImpl.searchImports(BundleWiringImpl.java:1618) ~[?:?]
        at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1548) ~[?:?]
        at org.apache.felix.framework.BundleWiringImpl.access$300(BundleWiringImpl.java:79) ~[?:?]
        at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1982) ~[?:?]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:351) ~[?:1.8.0_232]
        ... 27 more

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As the Logging points-out:

Caused by: java.lang.ClassNotFoundException: de.e_nexus.vr.tk.VRFrame not found by de.e-nexus.component [87]

What means Karaf is searching the VRFrame from the component submodule, which clearly does not exist.

That makes sense since all java packages are exported, the VRFrame's package is ambiguous. I followed what ?zkan pakdil said and renamed the java-packages to a unique name. Since that it works like a charm.

Thanks ?zkan! Your answer includes some usefull hints and the source of my problem was the ambiguous package-name.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...