I have the following problem:
I've deployed in Tomcat a JNLP and an executable JAR files. JNLP file should automatically download the JAR file and execute it. The JAR file is signed and verified.
This is done (the downloading part).
But when to execute the JAR main class (specified in the JNLP file), a problem occurs:
A part of the main class code is executed. Afterwards, when it tries to load a class that has a static final org.apache.log4j.Logger instance declared, it says an error.
Below are the representative parts of the JNLP file, the code and the error.
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" />
The 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 [sun.misc.Launcher$AppClassLoader#d9f9c3] class loader in the search.
log4j:ERROR Could not parse url [jar:http://localhost:8080/examples/DemoJar.jar!/log4j.xml].
java.io.FileNotFoundException: JAR entry log4j.dtd not found in
at com.sun.jnlp.JNLPCachedJarURLConnection.connect(Unknown Source)
at com.sun.jnlp.JNLPCachedJarURLConnection.getInputStream(Unknown Source)
at com.sun.org.apache.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.XMLDocumentScannerImpl$DTDDriver.dispatch(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.doConfigure(DOMConfigurator.java:618)
at 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)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at ro.codemart.installer.packer.ant.impl.nestedjar.Main.executeApplicationMainClass(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.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)
at java.lang.Thread.run(Unknown Source)
log4j:WARN No appenders could be found for logger (WizardRunner).
log4j:WARN Please initialize the log4j system properly.
Thank you!
I think the problem is missing log4j.jar - it's not specified or loaded by the .jnlp file. You mentioned in the previous answer that it's in your classpath, but how if you're running via WebStart? I believe your classpath is limited to what's defined in the .jnlp file.
Try adding
<jar href="log4j.jar" main="true" download="eager" />
to
<resources>
If you look in your stack trace the cause of the error is a FileNotFoundException for log4j.dtd. Look at how the DTD is referenced from your log4j.xml. Is the DTD included in your jar file? It needs to be in a place where the JVM can load it.
Yes, the log4j.dtd file comes embedded with log4j-1.2.12.jar. Also this log4j jar is in the classpath.
Related
I put together an app using java, selenium and JFrame. When I try to launch it in a JNLP page it gives me this error:
java.security.AccessControlException: access denied ("java.util.PropertyPermission" "com.google.appengine.runtime.environment" "read")
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPropertyAccess(Unknown Source)
at java.lang.System.getProperty(Unknown Source)
at com.gargoylesoftware.htmlunit.gae.GAEUtils.isGaeMode(GAEUtils.java:35)
at com.gargoylesoftware.htmlunit.util.URLCreator.getCreator(URLCreator.java:48)
at com.gargoylesoftware.htmlunit.util.UrlUtils.<clinit>(UrlUtils.java:44)
at com.gargoylesoftware.htmlunit.WebClient.<clinit>(WebClient.java:160)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.newWebClient(HtmlUnitDriver.java:296)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.createWebClient(HtmlUnitDriver.java:270)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.<init>(HtmlUnitDriver.java:136)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.<init>(HtmlUnitDriver.java:179)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.<init>(HtmlUnitDriver.java:175)
at googlePackage.GoogleClass.<init>(GoogleClass.java:21)
at googlePackage.GoogleClass.main(GoogleClass.java:31)
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.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)
at java.lang.Thread.run(Unknown Source)
My JNLP file
<?xml version="1.0" encoding="utf-8"?>
<jnlp
spec="1.0+"
codebase="http://localhost/Java/SignSelenium/GoogleScan"
href="TwitterScan.jnlp">
<information>
<title>FrameDemo2</title>
<vendor>The Java(tm) Tutorial</vendor>
<homepage href="http://localhost/Java/index.html"/>
<description>Frame2</description>
<description kind="short">buttons within containers</description>
<offline-allowed/>
</information>
<resources>
<j2se version="1.6+"/>
<jar href="GoogleScan.jar"/>
</resources>
<application-desc main-class="googlePackage.GoogleClass"/>
</jnlp>
My Class
http://pastebin.com/sY9PHhvF
I have signed all selenium jar files contained in this jar.
To do that action, the JNLP file needs to declare:
<security>
<all-permissions />
</security>
Put is just after the information section.
I have created a JNLP to load the applet and some native DLL files. Following are the codes of each components
JNLP
<?xml version="1.0" encoding="UTF-8"?>
<!-- href attribute contains relative path;
codebase attribute not specified -->
<jnlp href="myKad.jnlp">
<information>
<title>MyKad Reader Applet</title>
<vendor>MyKad</vendor>
</information>
<security>
<all-permissions/>
</security>
<resources>
<!-- Application Resources -->
<j2se version="1.6+" href="http://java.sun.com/products/autodl/j2se" />
<jar href="HLB_Mykad-0.0.1-SNAPSHOT.jar" main="true"/>
<nativelib href="HLB_Mykad-0.0.1-SNAPSHOT.jar" download="eager"/>
</resources>
<applet-desc
name="MyKad Applet"
main-class="com.glexim.applet.GleximApplet"
width="1"
height="1">
</applet-desc>
<update check="background"/>
</jnlp>
JAR (HLB_Mykad-0.0.1-SNAPSHOT.jar) Structure (JAR's are Packaged at top lavel)
com.glexim.applet.GleximApplet
META-INF
Sample.dll
HTML Code
<applet jnlp_href="./applet/myKad.jnlp"
code="com.glexim.applet.GleximApplet" id="gleximApplet"
mayscript="true" width="0px" style="" />
While loading applet I am getting following exception in applet console:
java.lang.RuntimeException: java.lang.UnsatisfiedLinkError: no Sample in java.library.path
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.UnsatisfiedLinkError: no Sample in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at com.glexim.zf1.MyKad$1.run(MyKad.java:19)
at java.security.AccessController.doPrivileged(Native Method)
at com.glexim.zf1.MyKad.<clinit>(MyKad.java:13)
at com.glexim.applet.GleximApplet.<init>(GleximApplet.java:43)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$12.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$400(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Exception: java.lang.RuntimeException: java.lang.UnsatisfiedLinkError: no Sample in java.library.path
My Applet is signed applet and all the DLL files inside applet are also signed with same signature.
Create other section in your JNLP file describing the native resources:
<resources os="Windows" arch="x86">
<nativelib href="jar-with-nativelibs.jar"/>
</resources>
(You don't have to use one jar for each os and architecture supported, but it's recommended)
And after that, define the java.library.path property:
<property key="java.library.path" value="." />
And you're good to go.
I new to web-start and We are using exe4j to create executable from One-jar. In-order to make a "web start version" of our application I am trying to lunch One-JAR using web start with the specified Main-Class but I am getting the following error -
java.security.AccessControlException: access denied (java.util.PropertyPermission one-jar.main-class read)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPropertyAccess(Unknown Source)
at java.lang.System.getProperty(Unknown Source)
at com.simontuffs.onejar.Boot.run(Boot.java:186)
at com.simontuffs.onejar.Boot.main(Boot.java:137)
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.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)
at java.lang.Thread.run(Unknown Source)
JNLP contains --
<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="" href="">
<information>
<title>Applet Takes Params</title>
<vendor>Protype example</vendor>
</information>
<resources>
<!-- Application Resources -->
<j2se version="1.5+"
href="http://java.sun.com/products/autodl/j2se"/>
<jar href="Application.jar" main="true" />
</resources>
<application-desc main-class="com.simontuffs.onejar.Boot">
</application-desc>
<update check="background"/>
</jnlp>
I am trying to launch a Application.jar directly and com.simontuffs.onejar.Boot is the main class specify for JAR. I am also found this link that says we can not launch One-Jar with web-start. please help.
access denied (java.util.PropertyPermission one-jar.main-class read)
A web start app. can access any property if it declares all-permissions. If it is sand-boxed, it can only access properties prefixed with jnlp & some other JRE properties that are considered 'safe'.
After finally solving the jar signing problem (thank you everyone for your help!), a new one has now come up.
When trying to launch the web start app from the launch.jnlp file I get the following error :
java.lang.NullPointerException
at com.sun.javaws.Launcher.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)
at java.lang.Thread.run(Unknown Source)
If I use the jnlp file that points to the jar file on my computer, the app runs fine, but if I try to use the jar file in the website - I get the above error.
What exactly is the problem?
The jnlp file has the right format, otherwise why would it work on my local jar file?
Here is the jnlp:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<jnlp spec="1.0+">
<information>
<title>ExcelReader</title>
<vendor>Adam</vendor>
<homepage href="http://www.appquad.com"/>
<description>ExcelReader</description>
<description kind="short">ExcelReader</description>
<offline-allowed/>
</information>
<update check="background"/>
<security>
<all-permissions/>
</security>
<resources>
<j2se version="1.7+"/>
<jar href="http://www.appquad.com/ExcelCopyApp/sExcelReader.jar" main="true"/>
<jar href="http://www.appquad.com/ExcelCopyApp/lib/jxl.jar"/>
</resources>
<application-desc main-class="excelreader.ExcelCopyApp">
</application-desc>
</jnlp>
Be sure that your JNLP file has the right format: http://download.oracle.com/javase/6/docs/technotes/guides/javaws/developersguide/syntax.html
I had faced similar issue. I was getting below exception while trying to launch
app through jnlp:
java.lang.NullPointerException
at com.sun.javaws.JnlpxArgs.execProgram(Unknown Source)
at com.sun.javaws.Launcher.relaunch(Unknown Source)
at com.sun.javaws.Launcher.prepareResources(Unknown Source)
at com.sun.javaws.Launcher.prepareAllResources(Unknown Source)
at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
at com.sun.javaws.Launcher.launch(Unknown Source)
at com.sun.javaws.Main.launchApp(Unknown Source)
at com.sun.javaws.Main.continueInSecureThread(Unknown Source)
at com.sun.javaws.Main.access$000(Unknown Source)
at com.sun.javaws.Main$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source).
I have jdk 1.7 on my machine and any how some jar in JRE lib was missing or corrupted. I have resinstalled the JRE and it worked for me. I would suggest to figure out jar that is not getting picked up from jnlp file and relplace them and see if it works.
I can use Java web start to start my Swing GUI application on the command line by the url with jdk 6 & Windows XP:
javaws http://localhost:7001/webstart/myapp/launch.jnlp
How to use Java web start to start my Swing GUI application on the command line by the file name?
The following ways do not work:
javaws -codebase '' launch.jnlp
java.net.MalformedURLException: no protocol: ''
at java.net.URL.(Unknown Source)
at java.net.URL.(Unknown Source)
at java.net.URL.(Unknown Source)
at com.sun.javaws.Main.parseArgs(Unknown Source)
at com.sun.javaws.Main.continueInSecureThread(Unknown Source)
at com.sun.javaws.Main$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
javaws -codebase "" launch.jnlp
java.net.MalformedURLException: unknown protocol: c
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at com.sun.javaws.Main.parseArgs(Unknown Source)
at com.sun.javaws.Main.continueInSecureThread(Unknown Source)
at com.sun.javaws.Main$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
javaws -codebase "file:." launch.jnlp
com.sun.deploy.net.FailedDownloadException: Unable to load resource: file:./$$name
at com.sun.deploy.net.DownloadEngine.actionDownload(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResource(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResource(Unknown Source)
at com.sun.javaws.Launcher.updateFinalLaunchDesc(Unknown Source)
at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
at com.sun.javaws.Launcher.launch(Unknown Source)
at com.sun.javaws.Main.launchApp(Unknown Source)
at com.sun.javaws.Main.continueInSecureThread(Unknown Source)
at com.sun.javaws.Main$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
javaws -codebase "file:." file://launch.jnlp
CouldNotLoadArgumentException[ Could not load file/URL specified: file://launch.jnlp]
at com.sun.javaws.Main.launchApp(Unknown Source)
at com.sun.javaws.Main.continueInSecureThread(Unknown Source)
at com.sun.javaws.Main$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
javaws file://launch.jnlp
CouldNotLoadArgumentException[ Could not load file/URL specified: file://launch.jnlp]
at com.sun.javaws.Main.launchApp(Unknown Source)
at com.sun.javaws.Main.continueInSecureThread(Unknown Source)
at com.sun.javaws.Main$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
#The following has no error message, but nothing appear on the computer screen:
javaws -codebase "" -J-Xrunjdwp:transport=dt_socket launch.jnlp
javaws -J-Xdebug -J-Xnoagent -J-Xrunjdwp:transport=dt_socket,server=n,suspend=y launch.jnlp
javaws -codebase "" -J-Xrunjdwp:transport=dt_socket,server=n,suspend=n launch.jnlp
javaws -codebase "" -J-Xrunjdwp:transport=dt_socket,server=y,suspend=n launch.jnlp
The launch.jnlp file is as follows:
<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+" codebase="$$codebase" href="$$name">
<information>
<title>${com.prod.my.myapp.common.client.title}</title>
<vendor>I</vendor>
<homepage href="http://devzone/english/dev%20template/html_templates/main.asp"/>
<description>${com.prod.my.myapp.common.client.description}</description>
<description kind="short">${com.prod.my.myapp.common.client.short_description}</description>
<icon href="$$context/images/chflag.jpg"/>
</information>
<security>
<all-permissions/>
</security>
<resources>
<java version="1.6.0_05" href="http://java.sun.com/products/autodl/j2se" max-heap-size="256m"/>
<!-- myapp Application -->
<jar href="myprod.myapp.client.jar"/>
<jar href="myprod.reports.jar"/>
<!-- TR Client jar -->
<jar href="extern.ejb-client.jar"/>
<property name="java.naming.factory.initial" value="weblogic.jndi.WLInitialContextFactory"/>
<property name="java.naming.provider.url" value="${com.prod.my.myapp.common.client.naming_provider}"/>
<property name="weblogic.jndi.enableServerAffinity" value="true" /
</resources>
<application-desc main-class="com.prod.my.myapp.common.framework.applicationmainwindow.gui.myappApÂplication"/
</jnlp>
Try a codebase value of..
"file:."
It seems your JNLP file should be used together with the JNLPDownloadServlet. It replaces the $$name and $$codebase palceholders with the current values based on the server where you application currently runs. (Btw. you can also use $$server to refer the current server)
If you run it locally from disk, you can overwrite the codebase by setting it on the command line as parameter -codebase. The right value is file:.. You problem is that the $$name placeholder is not replaced and it tries do download the <jnlp ... href="$$name"> which results to file:.$$name and since no such file exists it fails.
You can either completely omitt the href="$$name" attribute in the <jnlp /> tag when running locally or manually change it to the jnlp file name e.g. <jnlp ... href="myApp.jnlp" />.
Also remeber if you want to use some local jar stored on you disk and you want to refer it via absolute path you should use this format <jar href="file:c:/myJars/myJar.jar"> (forward slashes).
All the best.