Running test with Logback and Equinox (E4) fails

388 views
Skip to first unread message

Peter Haxxor

unread,
Mar 18, 2014, 7:19:56 AM3/18/14
to op...@googlegroups.com
Hi,
I have a problem to run my integration test using Equinox (Eclipse 4), Logback with Maven. I have the following:

pom.xml which contains:

<properties>
<exam.version>3.4.0</exam.version>
<url.version>1.6.0</url.version>
</properties>

...

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.16</version>
</dependency>
</dependencies>
</plugin>

...

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-container-native</artifactId>
<version>${exam.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-junit4</artifactId>
<version>${exam.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.ops4j.pax.runner</groupId>
<artifactId>pax-runner-platform-equinox</artifactId>
<version>1.8.5</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-link-mvn</artifactId>
<version>${exam.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.ops4j.pax.url</groupId>
<artifactId>pax-url-aether</artifactId>
<version>${url.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.ops4j.pax.swissbox</groupId>
<artifactId>pax-swissbox-tracker</artifactId>
<version>1.7.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-extender-service</artifactId>
<version>${exam.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.ops4j.pax.logging</groupId>
<artifactId>pax-logging-logback</artifactId>
<version>1.7.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.codehaus.janino</groupId>
<artifactId>janino</artifactId>
<version>2.6.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.1.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.1</version>
<scope>test</scope>
</dependency>

And a project structure
src/main/java/*.java
src/test/main/PaxExamTest.java
src/test/resources/exam.properties
src/test/resources/logback.xml

The exam.properties file contains
 pax.exam.logging = logback

And the PaxExamTest.java contains

@Inject
private BundleContext bc;

@Inject
private MyServiceClass c;

@Configuration
public Option[] config() {
return options(
cleanCaches(),
systemProperty("osgi.console").value("6666"),
systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("INFO"),

  systemProperty("logback.configurationFile").value("file:/......./src/test/resources/logback.xml"),

  mavenBundle("org.codehaus.janino", "commons-compiler", "2.6.1"),
  mavenBundle("org.codehaus.janino", "janino", "2.6.1"),
  mavenBundle("ch.qos.logback", "logback-core", "1.1.1"),
  mavenBundle("ch.qos.logback", "logback-classic", "1.1.1"),
  mavenBundle("org.slf4j", "slf4j-api", "1.7.6"),

  mavenBundle("my.common", "my.common", "0.0.1-SNAPSHOT"),
  mavenBundle("my.server", "my.server", "0.0.1-SNAPSHOT")
// org.ops4j.pax.exam.CoreOptions.junitBundles()
);


Where the plugin "my.server" provides a service (MyServiceClass) which "my.common" is using.

If I execute maven test, I get the following errors:

Failed to instantiate [ch.qos.logback.classic.LoggerContext]
Reported exception:
java.lang.NoClassDefFoundError: org/codehaus/janino/ScriptEvaluator
at ch.qos.logback.core.boolex.JaninoEventEvaluatorBase.start(JaninoEventEvaluatorBase.java:57)
at ch.qos.logback.core.joran.action.NestedComplexPropertyIA.end(NestedComplexPropertyIA.java:167)
at ch.qos.logback.core.joran.spi.Interpreter.callEndAction(Interpreter.java:317)
at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:196)
at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:182)
at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:149)
at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:135)
at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:99)
at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:49)
at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:75)
at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:150)
at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:85)
at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55)
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:129)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:108)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:302)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:276)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:288)
at org.ops4j.pax.swissbox.extender.BundleWatcher.<clinit>(BundleWatcher.java:58)
at org.ops4j.pax.exam.raw.extender.intern.Activator.start(Activator.java:42)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:711)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:702)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:390)
at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1176)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:559)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:544)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:457)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:243)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:438)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:1)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)
Caused by: java.lang.ClassNotFoundException: org.codehaus.janino.ScriptEvaluator cannot be found by ch.qos.logback.core_1.1.1
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:501)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 36 more

And

java.lang.ClassNotFoundException: my.server.MyServiceClass cannot be found by PAXEXAM-PROBE-708309a3-f1f0-4418-b0ec-b31eeaa06c6f_0.0.0


I really googled everything for hours but I did not find a solution...

Thank you very very much.


Peter Haxxor

unread,
Mar 18, 2014, 3:29:52 PM3/18/14
to op...@googlegroups.com
ok, I found out, that the maven dependency to org.codehaus.janino did not export the package. I downloaded the jar files and included them in my plugin. There I exported them. My application can run normally with Eclipse IDE, but the maven test is still failing with the error above, when I use my logback configuration file.

After I removed the configurationFile property, I was able to start the test class (so I will solve it later).
BUT: I still can't access the classes of the bundles I had added in the configuration section.
 my.server.MyServiceClass

What am I doing wrong? I can't find anything. The documentation is also very rare.

Christoph Läubrich

unread,
Mar 19, 2014, 3:43:26 AM3/19/14
to op...@googlegroups.com
If you have jars that don't export their packages and/or are plain jars you can use the wrap() Option. Beside this, make sure all dependencies are avaiable before your test starts. If you want Logback to load additional classes you might need to attatch a fragment with proper import packages.
--
--
------------------
OPS4J - http://www.ops4j.org - op...@googlegroups.com

---
You received this message because you are subscribed to the Google Groups "OPS4J" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ops4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael Täschner

unread,
Mar 24, 2014, 4:15:03 PM3/24/14
to op...@googlegroups.com
Hi,

just for information: currently the commons-compiler and janino
wrapped bundles are hosted by Spring EBR. As this will not be
maintained much longer the following issue was raised to manage the
artifacts as part of the servicemix bundles instead.

Ref:
https://issues.apache.org/jira/browse/SMX4-1726

Cheers,
Michael
Reply all
Reply to author
Forward
0 new messages