FULL PRODUCT VERSION :
java version "1.5.0_05"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_05-b05)
Java HotSpot(TM) Client VM (build 1.5.0_05-b05, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
Microsoft Windows 2000 [Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
Cannot load xml file resources from signed jar file (defined into the jnlp file), when the execution context includes a class loaded by a secondary classloader.
I have only experienced this problem with the JNLPClassLoader. I first ran into the problem with a custom classloader, but I can recreate the problem with the URLClassLoader. The problem does not occur when the app is run without webstart.
I can send a sample app which dupilcates the problem.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
PIECES OF TEST:
test.jar
- defined in jnlp
- contains JarCode.class
resouce.jar
- defined in jnlp
- contains ApplicationAnchor.class, Load_Before.xml, Load_After.xml
JarCode.java
- downloaded in test.jar
- contains the main method,
- action
- loads Load_Before.xml file from resource.jar
- loads DynCode.class from http web server using URLClassLoader
- loads Load_After.xml file from resource.jar
DynCode.java
- downloaded from http web server using URLClassLoader
- action - loads Load_Before.xml file from resource.jar
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
RESULTS when run from command line:
application/Load_Before.xml was loaded successfully
constuctor URLClassLoader and load class
********************* start DynCode constructor *********************
**
** anchor class name application.ApplicationAnchor
** classloader class name sun.misc.Launcher$AppClassLoader
** application/Load_Before.xml was loaded successfully
**
********************** end DynCode constructor **********************
application/Load_After.xml was loaded successfully
ACTUAL -
RESULTS when run from webstart:
Java Web Start 1.4.2_03 Console, started Wed Jun 23 16:39:24 EDT 2004
Java 2 Runtime Environment: Version 1.4.2_03 by Sun Microsystems Inc.
Logging to file: c:\ntm\log.txt
application/Load_Before.xml was loaded successfully
constuctor URLClassLoader and load class
********************* start DynCode constructor *********************
**
** anchor class name application.ApplicationAnchor
** classloader class name com.sun.jnlp.JNLPClassLoader
** application/Load_Before.xml was not loaded
**
********************** end DynCode constructor **********************
application/Load_After.xml was loaded successfully
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
JARCODE.JAVA
package net.jenzabar.test;
import java.io.InputStream;
import java.net.URLClassLoader;
import java.net.URL;
/**
* JarCode is loaded by the JNLPClassLoader. JarCode is loaded from the
* test.jar file, which in defined in the jnlp file.
*
*/
public class JarCode {
static final String RESOURCE_NAME = "application/Load_Before.xml";
static final String RESOURCE_NAME2 = "application/Load_After.xml";
private void loadInputStream(String fileName$) throws Exception {
try {
Class anchorClass = application.ApplicationAnchor.class;
ClassLoader classLoader = anchorClass.getClassLoader();
InputStream inputStream = classLoader.getResourceAsStream(fileName$);
System.out.println(fileName$ + (inputStream == null ? " was not loaded" : " was loaded successfully"));
} catch (Exception e) {
System.out.println("Error while trying to open xml file at: " + fileName$);
e.printStackTrace();
}
}
public JarCode() {
try {
loadInputStream(RESOURCE_NAME);
System.out.println("constuctor URLClassLoader and load class");
URL[] urls = new URL[] {new URL("http://10.20.10.67:8085/")};
URLClassLoader urlClassLoader = new URLClassLoader(urls, this.getClass().getClassLoader());
Class stub = urlClassLoader.loadClass("net.jenzabar.test.DynCode");
stub.newInstance();
loadInputStream(RESOURCE_NAME2);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
JarCode jarCode = new JarCode();
}
}
package net.jenzabar.test;
DYNCODE.JAVA
import java.io.InputStream;
/**
* DynCode is loaded using the URLClassLoader. DynCode is loaded from an
* hhtp server. It is not concluded in the test.jar.
*
*/
public class DynCode {
static final String RESOURCE_NAME = "application/Load_Before.xml";
public DynCode() {
System.out.println("************************** start DynCode constructor **************************");
System.out.println("**");
Class anchorClass = application.ApplicationAnchor.class;
System.out.println("** anchor class name " + anchorClass.getName());
ClassLoader classLoader = anchorClass.getClassLoader();
System.out.println("** classloader class name " + classLoader.getClass().getName());
InputStream inputStream = classLoader.getResourceAsStream(RESOURCE_NAME);
System.out.println("** " + RESOURCE_NAME + (inputStream == null ? " was not loaded" : " was loaded successfully"));
System.out.println("**");
System.out.println("*************************** end DynCode constructor ***************************");
}
}
LOAD_BEFORE.XML
<?xml version="1.0" encoding="UTF-8"?>
<bizobject name="LoadBefore"/>
LOAD_AFTER.XML
<?xml version="1.0" encoding="UTF-8"?>
<bizobject name="LoadAfter"/>
APPLICATIONANCHOR.JAVA
package application;
public class ApplicationAnchor
{
public ApplicationAnchor()
{
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
we are loading xml resources from the server
java version "1.5.0_05"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_05-b05)
Java HotSpot(TM) Client VM (build 1.5.0_05-b05, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
Microsoft Windows 2000 [Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
Cannot load xml file resources from signed jar file (defined into the jnlp file), when the execution context includes a class loaded by a secondary classloader.
I have only experienced this problem with the JNLPClassLoader. I first ran into the problem with a custom classloader, but I can recreate the problem with the URLClassLoader. The problem does not occur when the app is run without webstart.
I can send a sample app which dupilcates the problem.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
PIECES OF TEST:
test.jar
- defined in jnlp
- contains JarCode.class
resouce.jar
- defined in jnlp
- contains ApplicationAnchor.class, Load_Before.xml, Load_After.xml
JarCode.java
- downloaded in test.jar
- contains the main method,
- action
- loads Load_Before.xml file from resource.jar
- loads DynCode.class from http web server using URLClassLoader
- loads Load_After.xml file from resource.jar
DynCode.java
- downloaded from http web server using URLClassLoader
- action - loads Load_Before.xml file from resource.jar
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
RESULTS when run from command line:
application/Load_Before.xml was loaded successfully
constuctor URLClassLoader and load class
********************* start DynCode constructor *********************
**
** anchor class name application.ApplicationAnchor
** classloader class name sun.misc.Launcher$AppClassLoader
** application/Load_Before.xml was loaded successfully
**
********************** end DynCode constructor **********************
application/Load_After.xml was loaded successfully
ACTUAL -
RESULTS when run from webstart:
Java Web Start 1.4.2_03 Console, started Wed Jun 23 16:39:24 EDT 2004
Java 2 Runtime Environment: Version 1.4.2_03 by Sun Microsystems Inc.
Logging to file: c:\ntm\log.txt
application/Load_Before.xml was loaded successfully
constuctor URLClassLoader and load class
********************* start DynCode constructor *********************
**
** anchor class name application.ApplicationAnchor
** classloader class name com.sun.jnlp.JNLPClassLoader
** application/Load_Before.xml was not loaded
**
********************** end DynCode constructor **********************
application/Load_After.xml was loaded successfully
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
JARCODE.JAVA
package net.jenzabar.test;
import java.io.InputStream;
import java.net.URLClassLoader;
import java.net.URL;
/**
* JarCode is loaded by the JNLPClassLoader. JarCode is loaded from the
* test.jar file, which in defined in the jnlp file.
*
*/
public class JarCode {
static final String RESOURCE_NAME = "application/Load_Before.xml";
static final String RESOURCE_NAME2 = "application/Load_After.xml";
private void loadInputStream(String fileName$) throws Exception {
try {
Class anchorClass = application.ApplicationAnchor.class;
ClassLoader classLoader = anchorClass.getClassLoader();
InputStream inputStream = classLoader.getResourceAsStream(fileName$);
System.out.println(fileName$ + (inputStream == null ? " was not loaded" : " was loaded successfully"));
} catch (Exception e) {
System.out.println("Error while trying to open xml file at: " + fileName$);
e.printStackTrace();
}
}
public JarCode() {
try {
loadInputStream(RESOURCE_NAME);
System.out.println("constuctor URLClassLoader and load class");
URL[] urls = new URL[] {new URL("http://10.20.10.67:8085/")};
URLClassLoader urlClassLoader = new URLClassLoader(urls, this.getClass().getClassLoader());
Class stub = urlClassLoader.loadClass("net.jenzabar.test.DynCode");
stub.newInstance();
loadInputStream(RESOURCE_NAME2);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
JarCode jarCode = new JarCode();
}
}
package net.jenzabar.test;
DYNCODE.JAVA
import java.io.InputStream;
/**
* DynCode is loaded using the URLClassLoader. DynCode is loaded from an
* hhtp server. It is not concluded in the test.jar.
*
*/
public class DynCode {
static final String RESOURCE_NAME = "application/Load_Before.xml";
public DynCode() {
System.out.println("************************** start DynCode constructor **************************");
System.out.println("**");
Class anchorClass = application.ApplicationAnchor.class;
System.out.println("** anchor class name " + anchorClass.getName());
ClassLoader classLoader = anchorClass.getClassLoader();
System.out.println("** classloader class name " + classLoader.getClass().getName());
InputStream inputStream = classLoader.getResourceAsStream(RESOURCE_NAME);
System.out.println("** " + RESOURCE_NAME + (inputStream == null ? " was not loaded" : " was loaded successfully"));
System.out.println("**");
System.out.println("*************************** end DynCode constructor ***************************");
}
}
LOAD_BEFORE.XML
<?xml version="1.0" encoding="UTF-8"?>
<bizobject name="LoadBefore"/>
LOAD_AFTER.XML
<?xml version="1.0" encoding="UTF-8"?>
<bizobject name="LoadAfter"/>
APPLICATIONANCHOR.JAVA
package application;
public class ApplicationAnchor
{
public ApplicationAnchor()
{
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
we are loading xml resources from the server