Michael Muck
Michael Muck

Reputation: 31

How to use org.apache.logging.log4j.jul.LogManager in an eclipse-rcp application?

I am trying to use the log4j2 LogManager in an eclipse rcp application. I have

-Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager

set as start parameter. Starting the rcp application from within my eclipse IDE everything works as expected. But as soon as I start it as a standalone application logging won't work.

A possible hint may be the following stacktrace from the client console:

Could not load Logmanager "org.apache.logging.log4j.jul.LogManager"
java.lang.ClassNotFoundException: org.apache.logging.log4j.jul.LogManager
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at org.eclipse.core.runtime.internal.adaptor.ContextFinder.loadClass(ContextFinder.java:131)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.util.logging.LogManager$1.run(Unknown Source)
        at java.util.logging.LogManager$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.util.logging.LogManager.<clinit>(Unknown Source)
        at java.util.logging.Logger.demandLogger(Unknown Source)
        at java.util.logging.Logger.getLogger(Unknown Source)
        at org.apache.felix.gogo.runtime.threadio.ThreadIOImpl.<clinit>(ThreadIOImpl.java:30)
        at org.apache.felix.gogo.runtime.activator.Activator.start(Activator.java:75)
        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.start(AbstractBundle.java:300)
        at org.eclipse.equinox.console.command.adapter.Activator.startBundle(Activator.java:248)
        at org.eclipse.equinox.console.command.adapter.Activator.start(Activator.java:237)
        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.start(AbstractBundle.java:300)
        at org.eclipse.osgi.framework.internal.core.ConsoleManager.checkForConsoleBundle(ConsoleManager.java:215)
        at org.eclipse.core.runtime.adaptor.EclipseStarter.startup(EclipseStarter.java:297)
        at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:176)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
        at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
        at org.eclipse.equinox.launcher.Main.run(Main.java:1438)

What do I need to do to get logging running in the RCP application without starting it from within my IDE?

Upvotes: 2

Views: 2544

Answers (1)

John Mercier
John Mercier

Reputation: 1705

It sounds like eclipse is aware of your dependency on this class and is able to add it to the classpath for you. What you need is a way to add the dependency to the classpath when you run it outside of eclipse. To fix this, ensure the class org.apache.logging.log4j.jul.LogManager is on the classpath. This can be done with -cp and the path to the jar file. For example if you have a class com.org.Main you are trying to run.

java -cp your.jar:log4j-jul-2.3.jar com.org.Main

your.jar is the jar containing your application and log4j-jul-2.3.jar is the jar containing the missing class.

Upvotes: 1

Related Questions