Why is my Jnlp program not working with log4j?
I have the following problem: I have deployed JNLP and JAR executables to Tomcat. The JNLP file should automatically download the JAR file and execute it. The JAR file is signed and verified. This is done (loading part). But when there is a problem to execute the main JAR class (specified in the JNLP file): A portion of the main class code is executed. Subsequently, when it tries to load the class with a static final instance of org.apache.log4j.Logger, it reports an error.
Representative parts of the JNLP file, code, and error are shown below.
JNLP
<?xml version='1.0' encoding='UTF-8'?>
<jnlp spec="1.5+" codebase="http://localhost:8080/examples" href="DemoInstaller.jnlp" download="eager" main="true">
<information>
<title>Demo Installer</title>
<vendor>Codemart [www.codemart.ro]</vendor>
<homepage>https://sourceforge.net/projects/cminstall/</homepage>
<description>This is a demo installer built using Codemart Installer framework with JavaFX</description>
<description kind="tooltip">Codemart Demo Installer</description>
<offline-allowed />
<shortcut online="true">
<desktop />
</shortcut>
</information>
<security>
<all-permissions />
</security>
<update check="background" />
<resources>
<j2se href="http://java.sun.com/products/autodl/j2se" version="1.6+" />
<jar href="DemoInstaller.jar" main="true" download="eager" />
</resources>
<application-desc main-class="ro.codemart.installer.packer.ant.impl.nestedjar.Main" />
Main class:
public class Main {
public static void main(String[] args) throws Exception {
final Main main = new Main();
//this is the problem class !
Class clazz = Class.forName("WizardRunner");
Method m = clazz.getMethod("main", new Class[]{args.getClass()});
m.invoke(null, new Object[]{args});
...
}
}
And the problem class:
public class WizardRunner{
private final static Logger log = Logger.getLogger(WizardRunner.class);
...
}
And the error:
log4j: ERROR Could not find [log4j.dtd]. Used class loader [ sun.misc.Launcher$AppClassLoader@d9f9c3 ] in search. log4j: ERROR Unable to parse url [jar: http: // localhost: 8080 / examples / DemoJar.jar! /log4j.xml]... java.io.FileNotFoundException: JAR entry log4j.dtd not found at com.sun.jnlp.JNLPCachedJarURLConnection.connect (Unknown source) at com.sun.jnlp.JNLPCachedJarURLConnection.getInputStream (Unknown source) at com.source.source .xerces.internal.impl.XMLEntityManager.setupCurrentEntity (Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity (Unknown Source) at com.sun.org.apache.xerces.internal.impl .XMLEntityManager.startDTDEntity (Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.setInputSource (Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLDocumentTannerDScannerImpl $ DFD (Unknown source) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl $ DTDDriver.next (Unknown source) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl $ PrologDriver.next (Unknown source) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next (Unknown source) at com.sun.org.apache.xerces. internal.impl.XMLDocumentFragmentScannerImpl.scanDocument (Unknown source) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse (Unknown source) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration. parse (Unknown source) at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse (Unknown source) at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse (Unknown source) at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse (Unknown Source) at javax.xml.parsers.DocumentBuilder.parse (Unknown Source) at org.apache.log4j.xml.DOMConfigurator $ 2.parse (DOMConfigurator.java:612) at org.apache.log4j.xml.DOMConfigurator.doConfigure (DOMConfigurator.java:711) at org.apache.log4j.xml.DOMConfigurator:doConfigure18 org.apache.log4j.helpers.OptionConverter.selectAndConfigure (OptionConverter.java:470) at org.apache.log4j.LogManager. (LogManager.java:122) at org.apache.log4j.Logger.getLogger (Logger.java:117) at ro.codemart.installer.wizard.WizardRunner. (WizardRunner.java:38) in java.lang.Class.forName0 (native method) in java.lang.Class.forName (Unknown source) in ro.codemart.installer.packer.ant.impl.nestedjar.Main.executeApplicationMainClass file (Main.java:216) at ro.codemart.installer.packer.ant.impl.nestedjar.Main.main (Main.java:290) 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 com.sun.javaws.Launcher.exe com.sun.javaws.Launcher.exe comteApplication) (Unknown source. sun.javaws.Launcher.executeMainClass (Unknown source) at com.sun.javaws.Launcher.doLaunchApp (Unknown source) at com.sun.javaws.Launcher.run (Unknown source) in java.lang.Thread.run (Unknown source ) log4j: WARN No additions found for WizardRunner. log4j: WARN Please initialize the log4j system correctly.executeApplication (Unknown source) at com.sun.javaws.Launcher.executeMainClass (Unknown source) at com.sun.javaws.Launcher.doLaunchApp (Unknown source) at com.sun.javaws.Launcher.run (Unknown source) in java. lang.Thread.run (Unknown source) log4j: WARN No additions found for the logger (WizardRunner). log4j: WARN Please initialize the log4j system correctly.executeApplication (Unknown source) at com.sun.javaws.Launcher.executeMainClass (Unknown source) at com.sun.javaws.Launcher.doLaunchApp (Unknown source) at com.sun.javaws.Launcher.run (Unknown source) in java. lang.Thread.run (Unknown source) log4j: WARN No additions found for the logger (WizardRunner). log4j: WARN Please initialize the log4j system correctly.
Thanks!
I think the problem is missing log4j.jar - it is not listed or loaded by the .jnlp file. You mentioned in a previous answer that this is in your classpath, but how if you are working through WebStart? I believe your classpath is limited to what is defined in the .jnlp file.
Try adding
<jar href="log4j.jar" main="true" download="eager" />
to
<resources>
a source to share