Load multiple jars with Web Start

S

shahsachin

I have an application which I want to start through Java Web Start. Now
I also have some other plugin jars which are eventually loaded and used
by the main application. When I run the application stand-alone, it
works fine and also loads all the plugin jars flawlessly.

Now comes most annoying part.... I try the same through web start... I
signed all the jars and on the server the directory structure looks
like following...

htdocs/
mainapp.jar
mainapp.jnlp
jars/
plugin1.jar
plugin2.jar
plugin3.jar

after clicking the jnlp link, the main app loads up fine, but when i
try to bring up any of the plugins, I get the following exception
(which works fine if I run the stand alone):

java.util.zip.ZipException: The system cannot find the path specified
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(Unknown Source)
at java.util.jar.JarFile.<init>(Unknown Source)
at java.util.jar.JarFile.<init>(Unknown Source)
at mynamespace.PluginUIHelper.getPluginUIClass(PluginUIHelper.java:64)

The code snippet from PluginUIHelper.java looks like this:

......
62 if (serviceImpl.toLowerCase().endsWith(".jar")) {
63 try {
64 jarFile = new JarFile(serviceImpl);
65 } catch (IOException e) {
66 e.printStackTrace();
67 return null;
68 }
69
70 Manifest manifest = null;
71
72 try {
73 manifest = jarFile.getManifest();
74 } catch (IOException e) {
75 e.printStackTrace();
76 return null;
77 }
.......

So can anyone tell me what might be going wrong here? I had a similar
issue with the resource files, but it is solved by using
getClass().getClassLoader().getResource()

I am not sure if there is a similar way for solving dependent jar files
too. I will appreciate your help.

Thank you
Sachin
 
A

Aidan

I doubt it will find it since it's probably looking somewhere on the
local filesystem for the jar, but the jar is really on your webserver
and hasn't been downloaded yet. What does your jnlp file look like?
 
S

shahsachin

Thanks for your reply,

Here is my jnlp file:

=== Start mainapp.jnlp ===

<jnlp spec="1.0+"
codebase="http://myhost/"
href="mainapp.jnlp"
<!-- This information is shown to the user while they are loading the
app -->
<information>
<title>Sample App</title>
<vendor>ACME</vendor>
<homepage href="http://www.acme.com" />
<description>Sample application supporting plugins</description>
</information>
<offline-allowed/>
<security>
<all-permissions/>
</security>

<!-- Since 1.4+ is required for java web start to work,
we can leave this as is
-->
<resources>
<j2se version="1.4+" />
<jar href="mainapp.jar"/>
<jar href="jars/plugin1.jar"/>
<jar href="jars/plugin2.jar"/>
<jar href="jars/plugin3.jar"/>
</resources>

<application-desc main-class="mynamespace.MyMainClass" />
</jnlp>

==== End of File ====

As I mentioned before, the main app interface comes up fine using the
web start way. Also all the jars are signed.

Sachin
 
S

Smalltalker

Agreed that Rachel has a lot to offer to solve all the resource loader
related issues. But most of the utilities provided by Rachel needs
atleast the class name in order to load other resources from the given
jar. In my case, I first read the MANIFEST file from the plugin jars in
order to get the main class name for that jar. So the only input
available for my case is jar file name. I couldn't see anywhere in
Rachel utilities to load MANIFEST file from a given JAR file name. Is
there a way around for that?
 
S

Smalltalker

Alright, I solved the issue of loading a jar file and looking for its
MANIFEST file by putting all the required plugin jars inside the main
application jar and by using some code from
http://rachel.sourceforge.net/crossref/rachel/loader/JarResourceLoader.java.html

Now, another issue is when I try to instantiate the class from the
plugin jar, it complains about not finding one of the class which is
there inside the application jar mainapp.jar, I have my custom class
loader taking care of loading the plug-in jar classes. The exception
goes like this:

java.lang.NoClassDefFoundError: com/mf/tte/workbench/ServiceUI
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at
com.mf.tte.workbench.ServiceUIJarClassLoader.findClass(ServiceUIJarClassLoader.java:114)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at
com.mf.tte.workbench.ServiceUIHelper.getServiceUIClass(ServiceUIHelper.java:132)

I saw this posting
http://forum.java.sun.com/thread.jspa?threadID=607830&messageID=3317360
but, it is not working for me. Can anyone suggest me a solution?

Thanks
Sachin
 
S

Smalltalker

Fixed it, by using the class loader of the mainapp.jar

MyMainClass.class.getClassLoader().loadClass(name)

Thanks Aidan for your responses.

Sachin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top