tags:

views:

12

answers:

1

Hi, I have found MANY threads on packing all dependencies along with the project into one jar package, and it seems like there are many different ways to achieve this (oneJar, FatJar, Ant-build...)

So cooking up my own recipe, I have (after quite some effort) managed to package the project I am working on. In this one jar file, there is the code for the project plus all the jars that the project depends on which are loaded with jar-in-jar-loader that comes with eclipse. The resultant works fine on a number of different platforms, when it's ran through the terminal invoked via java -jar myjarfile.

Peachy, you might say, here's the problem though; when I sign my jar and try to run it via javaws (which is the ultimate goal here) I get an exception which I have decrypted to mean that libraries (in the case below org.apache.commons.lang.SystemUtils) are unaccessible.

So here's my question; is it not possible to load jars in jars when the applications is deployed for Java Web Start? If it is possible, what am I doing wrong? If not, what's the best alternative?

Thanks!


Below is the JNLP file along with the stackTrace I get when I run javaws myJNLPfile

<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+"
codebase="file:///home/ukirik/workspace/myproject/dist"
href="project.jnlp">

<information>
    <!-- Project info -->
</information>
<security>
    <all-permissions />
</security>
<resources os="Mac\ OS\ X">
    <j2se version="1.6+" java-vm-args="-XstartOnFirstThread"/>
</resources>
<resources>
    <jar href="myjar-jws.jar" />
</resources>
<application-desc main-class="org.gvt.RuntimeMain"/>            
</jnlp>

java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.javaws.Launcher.executeApplication(Launcher.java:1799)
at com.sun.javaws.Launcher.executeMainClass(Launcher.java:1745)
at com.sun.javaws.Launcher.doLaunchApp(Launcher.java:1507)
at com.sun.javaws.Launcher.run(Launcher.java:129)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/lang/SystemUtils
at org.gvt.RuntimeMain.loadSwtJar(RuntimeMain.java:27)
at org.gvt.RuntimeMain.main(RuntimeMain.java:13)
... 9 more
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.SystemUtils
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at com.sun.jnlp.JNLPClassLoader.findClass(JNLPClassLoader.java:332)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 11 more
A: 

It seems like the problem is with the classloader.

You may want to use a custom classloader in JWS, as described here:

http://lopica.sourceforge.net/faq.html#customcl

Depending on exactly what you need to do, in terms of packaging, there are a couple of options.

James Black
Thanks James, I have looked at the link you have provided. Though I have to say I haven't really made much sense out of it. When and where do I need to change the CL, and why? What I need is to pack a software that depends on a bunch of jars, to be deployed as JWS on different platforms. And to do that I need to selectively load swt-libraries, as I have mentioned above. Any tips?
posdef
If you want to be able to load jar files within jar files then I don't believe the standard classloader handles that, so by using a custom classloader you can get it to do what you want. You can just use the "jar in jar loader" that you mention in the question.
James Black