ClassNotFoundException: org.apache.felix.dm.DependencyActivatorBase with Pax Exam - java

I am using Pax Exam (3.5.0) for my OSGi unit tests. I have created a test but when I run it I get this stacktrace:
java.lang.NoClassDefFoundError: org/apache/felix/dm/DependencyActivatorBase
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.findClass(BundleWiringImpl.java:2279)
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1501)
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1955)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at org.apache.felix.framework.BundleWiringImpl.getClassByDelegation(BundleWiringImpl.java:1374)
at org.apache.felix.framework.Felix.createBundleActivator(Felix.java:4329)
at org.apache.felix.framework.Felix.activateBundle(Felix.java:2141)
at org.apache.felix.framework.Felix.startBundle(Felix.java:2064)
at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1291)
at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:304)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: org.apache.felix.dm.DependencyActivatorBase not found by com.company.wine.infrastructure [19]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1532)
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1955)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 14 more
I have configured CoreOptions.mavenBundle("org.apache.felix", "org.apache.felix.dependencymanager", "3.1.0") in the options and I see that org.ops4j.pax.logging.pax-logging-api[org.ops4j.pax.swissbox.extender.BundleWatcher] : Scanning bundle [org.apache.felix.dependencymanager] is loaded.
Still I get the exception. Anyone a clue on what I am doing wrong?
Cheers.

You have to differentiate in the way Pax Exam is designed and how you used it.
Pax Exams main use case is to use it in an integration test where you test a previously build artifact.
If you want to test it in the same module you have two ways of doing so.
1) in the Integrationtest-Phase of maven by referencing the freshly build artifact via a file: dependency.
2) by building a tiny-bundle containing your testable classes and other artifacts. This will need to also alter the Package-Imports/Exports in your test.
A sample of doing this can be found here

Related

Using javaagent with javassist in WildFly

I've written a simple javaagent that basically injects some logging in classes that are part of the JDK, such as javax/imageio/spi/ServiceRegistry, using javassist.
It works fine in a simple standalone application, but I cannot get it to work in WildFly 10. What I have tried:
Added the agent JAR as a module to WildFly along with the corresponding module.xml which declares <module name="org.javassist"/> as dependency
Appended the agent package and org.javassist to JBOSS_MODULES_SYSTEM_PKGS
Appended -javaagent:/full/path/to/agent/jar/in/module to JAVA_OPTS
WildFly starts but in server.log I get:
java.lang.NoClassDefFoundError: javassist/ClassPool
at net.luniks.agent.LoggerChanger.transform(LoggerChanger.java:48)
at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:428)
at java.lang.ClassLoader.findBootstrapClass(Native Method)
at java.lang.ClassLoader.findBootstrapClassOrNull(ClassLoader.java:1015)
at java.lang.ClassLoader.loadClass(ClassLoader.java:413)
at java.lang.ClassLoader.loadClass(ClassLoader.java:411)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.jboss.modules.ClassLoaderLocalLoader.loadClassLocal(ClassLoaderLocalLoader.java:74)
at org.jboss.modules.Module.loadModuleClass(Module.java:606)
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
It seems the module class loader is used but even though the agent module has a dependency to org.javassist, it still cannot load its classes.
What am I missing?
Eventually I got it to work by adding only the package of the agent to JBOSS_MODULES_SYSTEM_PKGS (not "javassist") and adding the org.javassist module JAR to the boot classpath:
JAVA_OPTS="$JAVA_OPTS -Xbootclasspath/p:/path/to/wildfly/modules/system/layers/base/org/javassist/main/javassist-3.18.1-GA.jar"
Now the agent works, it can load the Javassist classes. Certainly not the clean way but it is just for debugging purposes...

OSGi java.lang.NoClassDefFoundError: org/osgi/framework/BundleContext

I'm new with OSGi and I'm having trouble trying to run an example of this library: https://github.com/jitsi/libjitsi
java.lang.NoClassDefFoundError: org/osgi/framework/BundleContext
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
at java.lang.Class.getConstructor0(Class.java:3075)
at java.lang.Class.newInstance(Class.java:412)
at org.jitsi.service.libjitsi.LibJitsi.start(LibJitsi.java:247)
at org.jitsi.service.libjitsi.LibJitsi.start(LibJitsi.java:180)
at com.dotsystem.AVTransmit2.main(AVTransmit2.java:327)
Caused by: java.lang.ClassNotFoundException: org.osgi.framework.BundleContext
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
Do I need an external jar for osgi?
A class not found exception on a core osgi class, seems that you are missing a jar/framework jar that implements OSGi specification. Check which OSGi implementation your target system supports. If you have choice in choosing you can try,
Apache felix OSGi
Eclipse equinox OSGi
If you are trying to run example from IntelliJ it may be problem that you haven`t imported maven dependencies. When you import java project into IntelliJ you must also import its dependencies (they are not imported by default).

Class not found: org.springframework.context.ApplicationContext

I am new on Spring Framework. I had followed by instructions given in book Spring 4 for Professionals. In book author configured framework via xml, but I want configure it with Java. While running I'm getting ClassNotFoundException
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.springframework.context.ApplicationContext
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
I have published my code in
github.
What I'm doing wrong?
Works fine here, Hello World! is printed when I run it.
How do you try to run it?
I guess you tried to do java -jar spring-framework-example.jar.
This of course does not work because you miss the libraries in your classpath then.
If you exchange
jar {
manifest {
attributes 'Main-Class': 'com.bakhtiyor.sample.Application'
}
}
with
apply plugin: 'application'
mainClassName = 'com.bakhtiyor.sample.Application'
and then use gradle run, the application works fine.
PS: You should always use the Gradle Wrapper, even in the tiniest project. Then it is easier for others to build your project because nothing needs to be installed to build and the build always run with the Gradle version the build is designed for.

Spring java.lang.NoClassDefFoundError

I'm totally a newbie in springs so I wanted to try a helloworld program in springs. I came across this tutorial.
I downloaded the source code with library provided on this site, I have the latest Spring STS installed on my Eclipse Kepler. I got this error :
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.springframework.context.support.AbstractApplicationContext.(AbstractApplicationContext.java:153)
at org.springframework.context.support.AbstractApplicationContext.(AbstractApplicationContext.java:217)
at org.springframework.context.support.AbstractRefreshableApplicationContext.(AbstractRefreshableApplicationContext.java:88)
at org.springframework.context.support.AbstractRefreshableConfigApplicationContext.(AbstractRefreshableConfigApplicationContext.java:58)
at org.springframework.context.support.AbstractXmlApplicationContext.(AbstractXmlApplicationContext.java:61)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:136)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)
at com.vaannila.HelloWorldApp.main(HelloWorldApp.java:9)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 8 more
I also tried manually doing the entire program with a different class name and It throws the same error.
Things I have tried:
built path and included the springframework jars
also included commons-logging-1.1.1.jar
I got past this exception by adding commons-logging-1.1.1.jar to the classpath of my project. I had it in my maven repository from other projects.
Plus, to make the example work, the file name for the instantiation of ClassPathXmlApplicationContext needs to be qualified with the package path. If you are following the example exactly, you need to instantiate your context like this:
ApplicationContext context = new ClassPathXmlApplicationContext("com/vaannila/beans.xml");

Why does m2eclipse exclude resources from Eclipse build path?

I am trying out m2eclipse, the Eclipse plugin for Maven, and have noticed that the resources are now excluded from the build path of all my projects.
I have seen a question on the M2Eclipse FAQ page which seems to deal with this exact question, but the answer (paraphrased) seems to say that this is intentional to allow resource filtering, and everything Should Just Work.
However, when I run my application from within Eclipse, lots of my resources in dependent projects are failing to get found by my application.
I have tried my usual Eclipse waving-a-rubber-chicken actions (cleaning all projects, starting with -clean) to no avail. I'm sure I'm missing something fairly simple. Does anyone have any suggestions?
EDIT: Some digging in the m2 console has revealed that one of the projects is not building correctly. I get a ClassNotFoundException when it tries to find org.apache.maven.plugin.MojoFailureException in a custom plugin used to build one of the projects.
org.apache.maven.lifecycle.LifecycleExecutionException: Internal error in the plugin manager executing goal 'ourdemain:ourcustomplugin:2.0:process': Mojo execution failed.
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:505)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegmentForProject(DefaultLifecycleExecutor.java:265)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:191)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:149)
at org.apache.maven.DefaultMaven.execute_aroundBody0(DefaultMaven.java:223)
at org.apache.maven.DefaultMaven.execute_aroundBody1$advice(DefaultMaven.java:304)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:1)
at org.apache.maven.embedder.MavenEmbedder.execute_aroundBody2(MavenEmbedder.java:904)
at org.apache.maven.embedder.MavenEmbedder.execute_aroundBody3$advice(MavenEmbedder.java:304)
at org.apache.maven.embedder.MavenEmbedder.execute(MavenEmbedder.java:1)
at org.maven.ide.eclipse.internal.project.DefaultBuildParticipant$1.execute(DefaultBuildParticipant.java:130)
at org.maven.ide.eclipse.internal.project.MavenProjectManagerImpl.execute(MavenProjectManagerImpl.java:986)
at org.maven.ide.eclipse.internal.project.MavenProjectFacade.execute(MavenProjectFacade.java:320)
at org.maven.ide.eclipse.internal.project.DefaultBuildParticipant.executePostBuild(DefaultBuildParticipant.java:116)
at org.maven.ide.eclipse.internal.project.DefaultBuildParticipant.build(DefaultBuildParticipant.java:80)
at org.maven.ide.eclipse.internal.builder.MavenBuilder.build(MavenBuilder.java:84)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:633)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:170)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:201)
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:253)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:256)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:309)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:341)
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:140)
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:238)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Caused by: org.apache.maven.plugin.PluginExecutionException: Mojo execution failed.
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:601)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:498)
... 27 more
Caused by: org.apache.maven.plugin.MojoExecutionException: org/apache/maven/plugin/MojoFailureException
at org.codehaus.mojo.ruby.DefaultRubyMojo.execute(DefaultRubyMojo.java:98)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:579)
... 28 more
Caused by: java.lang.NoClassDefFoundError: org/apache/maven/plugin/MojoFailureException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
at java.lang.Class.getConstructor0(Class.java:2699)
at java.lang.Class.getConstructor(Class.java:1657)
at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:587)
at org.jruby.javasupport.Java.new_proxy_instance(Java.java:570)
at org.jruby.javasupport.JavaInvokerSnew_proxy_instancexx1.call(Unknown Source)
at org.jruby.runtime.callback.InvocationCallback.execute(InvocationCallback.java:49)
at org.jruby.internal.runtime.methods.FullFunctionCallbackMethod.internalCall(FullFunctionCallbackMethod.java:79)
at org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:79)
at org.jruby.evaluator.EvaluationState.callNode(EvaluationState.java:577)
at org.jruby.evaluator.EvaluationState.evalInternal(EvaluationState.java:206)
at org.jruby.evaluator.EvaluationState.setupArgs(EvaluationState.java:2182)
at org.jruby.evaluator.EvaluationState.attrAssignNode(EvaluationState.java:481)
at org.jruby.evaluator.EvaluationState.evalInternal(EvaluationState.java:191)
at org.jruby.evaluator.EvaluationState.blockNode(EvaluationState.java:522)
at org.jruby.evaluator.EvaluationState.evalInternal(EvaluationState.java:200)
at org.jruby.evaluator.EvaluationState.eval(EvaluationState.java:163)
at org.jruby.internal.runtime.methods.DefaultMethod.internalCall(DefaultMethod.java:167)
at org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:79)
at org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:125)
at org.jruby.evaluator.EvaluationState.callNode(EvaluationState.java:564)
at org.jruby.evaluator.EvaluationState.evalInternal(EvaluationState.java:206)
at org.jruby.evaluator.EvaluationState.callNode(EvaluationState.java:544)
at org.jruby.evaluator.EvaluationState.evalInternal(EvaluationState.java:206)
at org.jruby.evaluator.EvaluationState.localAsgnNode(EvaluationState.java:1230)
at org.jruby.evaluator.EvaluationState.evalInternal(EvaluationState.java:285)
at org.jruby.evaluator.EvaluationState.rescueNode(EvaluationState.java:1522)
at org.jruby.evaluator.EvaluationState.evalInternal(EvaluationState.java:349)
at org.jruby.evaluator.EvaluationState.ensureNode(EvaluationState.java:980)
at org.jruby.evaluator.EvaluationState.evalInternal(EvaluationState.java:246)
at org.jruby.evaluator.EvaluationState.eval(EvaluationState.java:163)
at org.jruby.internal.runtime.methods.DefaultMethod.internalCall(DefaultMethod.java:167)
at org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:79)
at org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:125)
at org.jruby.evaluator.EvaluationState.fCallNode(EvaluationState.java:1019)
at org.jruby.evaluator.EvaluationState.evalInternal(EvaluationState.java:252)
at org.jruby.evaluator.EvaluationState.blockNode(EvaluationState.java:522)
at org.jruby.evaluator.EvaluationState.evalInternal(EvaluationState.java:200)
at org.jruby.evaluator.EvaluationState.rootNode(EvaluationState.java:1622)
at org.jruby.evaluator.EvaluationState.evalInternal(EvaluationState.java:355)
at org.jruby.evaluator.EvaluationState.eval(EvaluationState.java:163)
at org.jruby.Ruby.eval(Ruby.java:274)
at org.codehaus.plexus.component.jruby.JRubyRuntimeInvoker.runInterpreter(JRubyRuntimeInvoker.java:392)
at org.codehaus.plexus.component.jruby.JRubyRuntimeInvoker.invoke(JRubyRuntimeInvoker.java:313)
at org.codehaus.mojo.ruby.DefaultRubyMojo.execute(DefaultRubyMojo.java:81)
... 29 more
Caused by: java.lang.ClassNotFoundException: org.apache.maven.plugin.MojoFailureException
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
... 75 more
The resource filtering mentioned in the FAQ is run whenever the Maven builder is run on the project. In practice I've found this to be more trouble than it's worth as the Maven builder runs quite slowly, and is only run when configured (which by default is only on a full build), leaving you to scratch your head and wonder why your changes aren't picked up.
I tend to modify the Eclipse classpath to include src/main/resources. This is sufficient for most use cases.
For the cases where the simple approach doesn't work (for example if a dependent project has some complicated resource processing), I do as Robert suggests and turn off workspace resolution, then install the dependency to the local repository so it is included in the Maven classpath container.
Try switching between the embedded ( 3.0 AFAIK ) Maven runtime and the one you use to perform your builds ( locally installed ).
Maven installations http://img150.imageshack.us/img150/6193/m2eclipseinstallations.png

Categories

Resources