• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JNLP ( External Library and Executable Jars )

 
Robin John
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have an Swing Desktop application where I need to run an applet ( due to old tradition, which they don't want to change and due to some browser dependencies ) and that applet launching an executable jar using Runtime.exec()

I have been trying to use JNLP for this and have a few questions before I implement.

The design:
1 - Servlet is hit
2 - Applet is launched
3 - Applet executes Swing main class

#1 - My swing application along with the dependency libraries is a massive 60 MB required for 10,000 users.
- Should I go ahead with Web Start ?
- If yes, Can I download just the specific jars and include an external library location for common libraries, is it possible ?
#2 - if possible, How do I include the external library location ( not downloading the jars from server via jnlp file)
#3 - Currently when I try to execute the Runtime.exec without specifying any file location, it's not executing, I'm getting a "not able to access the jar file" error. (Unable to find jarfile MyApp.jar) - Can I pass in a directory location before I start the Swing main class, do I need to ?

I have more questions but after I get some help with this.

Thank you guys in advance !
 
Tony Docherty
Bartender
Posts: 3054
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. If you have to provide an applet then the users are going to have to download the jar containing the applet and all other jars the applet needs regardless of how you deploy it and JNLP appears to be the preferred deployment method these days so I'd go with JNLP.
By external library location I'm assuming you mean leaving the libraries on the server so the user doesn't have to download them. AFAIK you can only do this if the server executes the library code so you'd have to implement a mechanism for the applet to call the server to run the required code and return the answer which I guessing is not the solution you are after.
2. see above.
3. I'm not sure what you mean by this, can you show some code. Note if the applet is call Runtime.exec() you will almost certainly have to provide a policy file which grants permission to the applet to do this.
 
Robin John
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the response Tony,

I have added my jnlp to the web app now and 'm downloading a few jars (all signed) from the server and a few jars (all signed) from the local C drive from my client system.

my JNLP is as follows



I have my component library.jnlp as follows



But Now I am getting an error as follows:



Everything works from local system, however fails when I deploy it to the server. I have tried giving local permissions, lowering java security settings, adding exceptions to local folder but in vain :(

Any idea on what I'm doing wrong ?

Thank you !
 
Paul Clapham
Sheriff
Posts: 21588
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're downloading the JNLP from the server (as you should be) then this is wrong:



You need a URL on the server, just like the other URLs in that spec document. (A relative URL should be fine. ) It doesn't make sense to expect the client to have the jar already on their system.
 
Robin John
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree Paul, however, due to the size 64 MB of all the files, I was trying to do partial download ( files which change frequently ) from server and the other stable jars already installed to my clients systems. ( fyi - I have a fixed set of client machines ).

- Can I do it this way ? is it allowed ?
- if not possible, my next question would be, will JWS able to handle this load ? will it cause any bandwidth / performance issues in production, I have around 10000 users who will launch the application every morning, don't want to make it too slow.
 
Tony Docherty
Bartender
Posts: 3054
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know if this will help but I found an SO thread that suggests you need to include 'localhost' in the codebase path. ie:
 
Robin John
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the response Tony, Unfortunately it didn't work too :(



My problem is exactly as stated here:

https://community.oracle.com/thread/3567167
 
Tony Docherty
Bartender
Posts: 3054
59
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One of the replies to that post is a link to the bug database (http://bugs.java.com/bugdatabase/view_bug.do?bug_id=7020285) and that bug has the following evaluation:

Oracle Bug Database wrote:according the forum, the user is trying to implement offline mode with a browser http doc base and a local file path codebase in applet tag.

In order to do offline mode, every bits needs to be on the local system, including the html/js loaded by the browser.

If I understand the posting in forum correctly, they are trying to load the html via browser, using a http URL, e.g:

http://your_host.com/applet.html

And inside applet.html, customer have codebase pointing to c:\some_files

This will not work due to security reasons. And most browser blocks this too, e.g:



won't load either by a browser, if the html is loaded via http://your_host.com/img.html

So if customer want to use codebase with a local path, the browser html/js file itself needs to be loaded from the local file system too.


So it looks like it's a browser based restriction rather than a JNLP issue.
 
Paul Clapham
Sheriff
Posts: 21588
33
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Robin John wrote: - if not possible, my next question would be, will JWS able to handle this load ? will it cause any bandwidth / performance issues in production, I have around 10000 users who will launch the application every morning, don't want to make it too slow.


Isn't there some capability for caching in JWS? I know when I used it you could see (via the Java console) jars and other resources which it had cached locally.
 
Robin John
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Paul, Tony,

Now I'm trying to implement everything on server side and with caching... Now the current sequence is,

I download two jars via jnlp, foo and soo, out of which foo has my applet


my applet launches successfully, now I want to execute my main class inside my soo.jar, Runtime.exec doesn't work inside MyAppLauncher applet.



I always get "Unable to access jarFile soo.jar.... :(

It has loads of arguments so I cannot launch soo.jar as another jnlp main class, I always get an invalid argument exception.

Is there any way I can access soo.jar main class using Runtime.exec inside my jnlp applet class ?
 
Paul Clapham
Sheriff
Posts: 21588
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Robin John wrote:Is there any way I can access soo.jar main class using Runtime.exec inside my jnlp applet class ?


I'm confused about why you would want to do that. (It doesn't help that it's unclear how your call to Runtime.exec() actually references that jar.)
 
Robin John
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apologies, I should have mentioned how my getArgs method provides the entire command.

the getArgs method actually forms a command line.

java.exe -jar soo.jar <many arguments> <some paths> <etc>

anyway, earlier I used to pass in the working directory to the applet in this command under C:\drive but now since I am trying to convert it to Jnlp applet, I have removed the working directory and the cached applet is unable to find the soo.jar.

so earlier I had

java.exe -jar C:\drive\soo.jar <many arguments> <some paths> <etc>

and everything was fine. but when I removed the path, hoping that the soo.jar will be automatically be picked up from the classpath. but looks like it doesn't.

How do I pass in the cached location to be able to start the jar ?
 
Tony Docherty
Bartender
Posts: 3054
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but when I removed the path, hoping that the soo.jar will be automatically be picked up from the classpath

Your new instance of java.exe won't inherit the classpath of the parent java.exe so unless all of your users have a CLASSPATH environment variable set to the correct location you will need to pass the classpath you require it to use as part of the arguments.
 
Robin John
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup Tony, all I am after is, If I'm downloading the jars via JNLP file then what do I set as the classpath ?
 
Paul Clapham
Sheriff
Posts: 21588
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're downloading the jars via JNLP then I'm still not understanding why you need to call Runtime.exec() to use them. Your Java code already has access to those jars, so why can't you access them directly from the JNLP code?
 
Robin John
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul, is it so ? I assumed, even if I download the dependent jars in my JNLP file, they are not added to the classpath. foo.jar and soo.jar are not dependent. Now I'm thinking of calling one from the other.

How do I access the class to launch the main class in soo.jar from the foo.jar applet ?
 
Paul Clapham
Sheriff
Posts: 21588
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You do a few minutes of research to find out what the main class is. Let's suppose it's called SooMainClass. Then to call its public static main method you first construct a string array containing the command-line parameters you want to pass to the method, and then like this:



But I'm still a bit confused about why this isn't just the main class configured into the JNLP in the first place. What's the purpose of having JNLP run some other class which then runs this one?
 
Robin John
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul, just got it resolved.. Duh ! me asked you that question.

I would love to do that, calling the jnlp to load my main class, but I would have to pass in parameters ( loads of them ), how to pass in my arguments to my jnlp main class dynamically ?

Also, I notice, jnlp is easily handling the downloads, 64MB worth of jars in less than a jiffy !!
 
Paul Clapham
Sheriff
Posts: 21588
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Robin John wrote:I would love to do that, calling the jnlp to load my main class, but I would have to pass in parameters ( loads of them ), how to pass in my arguments to my jnlp main class dynamically ?


Perhaps this old thread might help: How to make a JNLP file take dynamic parameter
 
Robin John
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul, I will try that.

However, there is another problem, in my soo.jar I want to read another jar's manifest attribute, how do I get hold of the jar file to read the attributes ?
 
Paul Clapham
Sheriff
Posts: 21588
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This may be getting a bit repetitious, but I don't understand why you would want to do that. Probably you thought at some point that would be a solution to a problem that you had, but I think it's likely that there are better (i.e. more normal) solutions.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic