A DESCRIPTION OF THE REQUEST :
JRunscript option "-cp" allows to load any jar, but importPackage() in JavaScript (JS) will fail with "new" package names, which are not already existing on start.
Example: compile two classes (into a jar) with two packages: "de" and "com". While com loads fine and is usable, de gets an error, as if the (same) jar does not contain these classes.
JUSTIFICATION :
The error produced is very misleading and there is no documentation telling you why packages are not loaded. It looks like a classpath or VM-classpath issue, while it is none.
Importing packages from jars should be possible for all top-level packages, as country-code specific packages are (or were) common practice.
At least the error should be more helpful in such a case.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Setting classpath and trying to import OrgStatics in package "org" works fine:
C:\Programme\Java\jdk1.6.0_10\bin>jrunscript.exe -cp C:\JsLib.jar
js> importPackage(org)
js> OrgStatics.hello()
Hello World
ACTUAL -
Setting classpath and trying to import fails with "de" (country-specific package name):
C:\Programme\Java\jdk1.6.0_10\bin>jrunscript.exe -cp C:\JsLib.jar
js> importPackage(de)
script error: sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "de
" is not defined. (<STDIN>#1) in <STDIN> at line number 1
js> DeStatics.hello()
script error: sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "De
Statics" is not defined. (<STDIN>#1) in <STDIN> at line number 1
---------- BEGIN SOURCE ----------
//these examples are stripped down while copying them here. i guess they work, but you get the picture anyways
//OrgStatics.java
package org;
public class OrgStatics {
public static String hello() {
return "Hello World";
}
}
//DeStatics.java
package de;
public class DeStatics {
public static String hello() {
return "Hello World";
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
None. Rename packages to com, org or whatever.