This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes distributing Java apps Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "distributing Java apps" Watch "distributing Java apps" New topic
Author

distributing Java apps

Derik Davenport
Ranch Hand

Joined: May 30, 2011
Posts: 53
This seems like a common question but I did a search and didn't find anything.

I have a app developed in NetBeans and the distribution folder contains a .JAR file and a LIB directory. When it came time to distribute I just zipped it up, and put it on the archive (.zip) file on a website. All the user needs to do is to unzip the archive and click on the Jar file. Simple. But instead of that, a significant fraction will view the archive contents and double click on the jar file. My application will not run from inside the archive (you will get some error about not being able to find main or whatever). And this generates a tech support call. This happens even with moderately advanced users. Heck, I sent a copy to another computer programmer and he did the same thing (he figured it out on his own but not until after he fired off an email complaining).

Is there a better way to lump the .JAR file and the corresponding library directory into a single (Jar) executable, preferably without changing all my executable code. For example, could I just wrap the application(.JAR) and the Lib directory in another Jar, so that the user could just click on the resulting wrapper file? What "manifest" files would be necessary to make that happen?

One behavior that may complicate the wrapper solution is that my program currently generates a configuration file (to save settings) in the same directory as the .JAR file. If the program is running from inside the wrapper, I am not sure how that would work. I could move the location to outside the wrapper but I am not sure how to access it then from within my program.





Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

If you've got a web site then the way to distribute your application is through Java Web Start. It takes care of the details like making sure the client machine has Java installed, and the right version of Java. It also takes care of distributing updates when they occur. So check that out.
Derik Davenport
Ranch Hand

Joined: May 30, 2011
Posts: 53
I looked into Java Web Start. At first it looked like the perfect solution to a lot of problems. But I immediately ran into questions I couldn't answer and so I was forced to abandon it.
Perhaps someone could point me to a web site with answers to questions like the ones I list below.

  • How does a user of my program, start it when he is not connected to the internet? would that depend on his OS? Most users wouldn't need to do this, but there would be some for which this would be essential
  • What knowledge must my web master have, in order to include the webstart link on our website?
  • How do I take a distribution (the .jar file and the Lib directory) and make them ready for webstart? Do I need special tools from oracle for that?
  • What are the server requirements? What files/programs would run on the server side? How complex is the installation.


  • Paul Clapham
    Bartender

    Joined: Oct 14, 2005
    Posts: 18541
        
        8

    Derik Davenport wrote:How does a user of my program, start it when he is not connected to the internet? would that depend on his OS? Most users wouldn't need to do this, but there would be some for which this would be essential


    He clicks on the shortcut which was put onto his machine when he first downloaded and installed the application. (You do need network access to the server to download the application.)

    What knowledge must my web master have, in order to include the webstart link on our website?


    As I recall, the single hard thing was to get the webmaster to install the MIME type for JNLP files. (Which is basically trivial.)

    How do I take a distribution (the .jar file and the Lib directory) and make them ready for webstart? Do I need special tools from oracle for that?


    No special tools required. Reading the Web Start documentation should be sufficient, and it's not anywhere near 100 pages anyway.

    What are the server requirements? What files/programs would run on the server side? How complex is the installation.


    I already described the installation (configuring the MIME type). Ours is running on an instance of Microsoft IIS which is unchanged except for that one thing.
    Derik Davenport
    Ranch Hand

    Joined: May 30, 2011
    Posts: 53
    Paul,

    First, this is starting to turn into a JWS conversation and I am wondering if it should be in a different forum.

    Where could I go to get some help doing this.
    According to this web page under the section titled "what do I need to change" I must first change the output of NetBeans so that it combines all the distribution files into a single .JAR file or a set of .JAR files. I don't know how to do that.

    Actually seeking out the WebStart in NetBeans, I was able to configure my application for web deployment. When I did a build, it created a JNLP file in the distribution directory. But I don't know what to do with it. If I copy it to its own directory, then double click on it, I can see the Java web start launcher kick in, but then I get the "Unable to launch the application" error.


    com.sun.deploy.net.FailedDownloadException: Unable to load resource: file:/C:/Projects/New Folder/$$codebase/launch.jnlp
    at com.sun.deploy.net.DownloadEngine.actionDownload(Unknown Source)
    at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)
    at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)

    Maybe I don't have some of the setting correct in NetBeans' "Web Start Page". Or maybe there is more work I need to do to my application to make it work. There were numerous references about the need to change the "classloader" when loading resources.


    He clicks on the shortcut which was put onto his machine when he first downloaded and installed the application.

    When does this action take place? Does that work in a cross platform way? I don't think can put application shortcuts on a OSX desktop (only documents). They have to go in the little pop up bar at the bottom. (I don't use OSX so I could be wrong about that). But it does seem like that would be OS dependant behavior that would have to be performed by the JVM.

    e single hard thing was to get the webmaster to install the MIME type for JNLP files

    I found on the same page as above, some instructions for doing that with Apache (my personal webserver). But I don't know what that does. It is my understanding that the JNPL runs locally on the client's copy of the JVM. Is that correct? What does the Webserver have to do with it?







    Rishi Shah
    Ranch Hand

    Joined: Sep 05, 2012
    Posts: 43

    What's wrong with just distributing the Jar file?
    Derik Davenport
    Ranch Hand

    Joined: May 30, 2011
    Posts: 53
    I can't distribute the JAR by itself, I will be missing the swing and JNA libraries that the application depends on (but which are not part of the JVM).


    Derik Davenport
    Ranch Hand

    Joined: May 30, 2011
    Posts: 53
    I have made some progress though.


    One of the help files for NetBeans led me to believe that word $$codebase (see the error above) was going to being magically changed to something useful. But according to this page you must edit yourself with the URL of your webserver.

    Once I did that, the JNLP file will launch JWS and download the app to some directory like "C:\Documents and Settings\...\Application Data\Sun\Java\Deployment" . The config file and archive files are placed in the same directory as the JNLP file however so at the least the user can find those quickly if he needs to do so. To run the program in "off line" mode it is sufficient to lick on the JNLP file again.

    I did not get an offer to put an "icon on the desktop" when I run the program.
    I google search of JNLP and "desktop icon" revealed this web site gave me some mods to my JNLP to do that. They didn't work for me though. I can generate them manually though the Java tool in the Control panel, but the typical end user wouldn't know about that (and besides it is OS specific).


    Paul Clapham
    Bartender

    Joined: Oct 14, 2005
    Posts: 18541
        
        8

    Why don't you just read up on JNLP and get the job done yourself? Here's a link to the tutorial and here's a link to the documentation for the JNLP file. It seems like you're trying to get Netbeans to do the work, but you still have to understand how JNLP works and what its features are as well as figure out how to get Netbeans to do what you want. I would just skip the Netbeans part and get it done.
    Rishi Shah
    Ranch Hand

    Joined: Sep 05, 2012
    Posts: 43

    Derik Davenport wrote: I can't distribute the JAR by itself, I will be missing the swing and JNA libraries that the application depends on (but which are not part of the JVM).




    And why can't you package them inside the Jar? Is it due to licensing restrictions?
    Derik Davenport
    Ranch Hand

    Joined: May 30, 2011
    Posts: 53

    Thanks for the JNLP references! I had not found that discussion previously in my research.

    I would just skip the Netbeans part and get it done.


    Well I expected that there was a very simple solution. I figured this is something every java programmer ran into the very first time they wanted to distribute an application. I am looking for the "single click solution" because I expected there would be one (if not several). JNLP looks extremely cool, but it is not a single click solution.

    As for getting NetBeans to do it for me, it looks as if it is going to take about 20 hours or so to learn all the in's and out's of XML and then JNLP and then Java Web Start. If it were my time, I would totally spend it. But my time is valuable to the company so I didn't want to re-invent the wheel if (and only if) I didn't need to do that. Moreover, unlike traditional (.zip file) distribution, it seems as if JNLP requires me to pay a Certificate Authority to authorize my applications. But after an hour or so of searching on Google, I can't even find a list of which root certificates are accepted by Java!

    Verisign has been mentioned explicitly a few times as being on the list. I don't know that their prices are typical but if it is going to cost $300+ a year to use JNLP, then it will be cheaper to just let tech support answer the same call about the .ZIP file 100 times a year.






    Derik Davenport
    Ranch Hand

    Joined: May 30, 2011
    Posts: 53
    And why can't you package them inside the Jar? Is it due to licensing restrictions?

    That sounds promising. How would I go about doing that exactly? Sorry if that sounds extremely noobish. I focused more on the details of how Java worked and less on the details of distribution until just recently.


    As I understand it, a Jar file is just a zip file with some extra bits (like a manifest file). These extra bits are used to tell the JVM which class to open up to find Main (among other things). So I would probably have to make up the manifest manually. Then I would need some kind of "archival tool" to create the Java ARchive. Is that all there is to it?
    Rishi Shah
    Ranch Hand

    Joined: Sep 05, 2012
    Posts: 43

    Derik Davenport wrote:
    And why can't you package them inside the Jar? Is it due to licensing restrictions?

    That sounds promising. How would I go about doing that exactly? Sorry if that sounds extremely noobish. I focused more on the details of how Java worked and less on the details of distribution until just recently.


    As I understand it, a Jar file is just a zip file with some extra bits (like a manifest file). These extra bits are used to tell the JVM which class to open up to find Main (among other things). So I would probably have to make up the manifest manually. Then I would need some kind of "archival tool" to create the Java ARchive. Is that all there is to it?


    You would pack everything you need inside your Jar file and load the resource as a stream ( http://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#getResourceAsStream(java.lang.String) ).

    If you need the resources as an actual physical file, you could write them to a temporary location after loading them.
    Paul Clapham
    Bartender

    Joined: Oct 14, 2005
    Posts: 18541
        
        8

    Derik Davenport wrote:Moreover, unlike traditional (.zip file) distribution, it seems as if JNLP requires me to pay a Certificate Authority to authorize my applications.


    You can always generate your own certificate, if you're just distributing your application to people you already know and not to the general public. This costs you nothing. And you don't even need to sign your application at all unless it does insecure things. Which quite likely it does, but you should look into that too.
    Derik Davenport
    Ranch Hand

    Joined: May 30, 2011
    Posts: 53
    You would pack everything you need inside your Jar file and load the resource as a stream

    I use a lot of resources files. Primarily I use text files internationalization graphic images to display information in a non-language specific manner. It might be difficult to go through all the code and change how those resources are loaded. Not impossible, but certainly non-trivial.

    if you're just distributing your application to people you already know and not to the general public.
    Unfortunately, this is going to the general public. And that is the problem. Most of my personal friends would recognize the difference between viewing the contents of a zip file and extracting the zip file. But the general public is not so savvy. I had one guy, who swore up and down that he was an expert with windows, proceed to extract the file to its own directory. But then would resolutely re-examine the zip archive to run the program rather than going to the new directory. It was as if he expected "extraction" to occur "in place". Anyway, that was just one guy. the people in tech support have to do this every day, and they are all saints - I could never do it. But I look for ways to make their lives easier, and I figured this was a nut that I could crack pretty easily.

    But every approach seems to be more difficult than the last. Manually wrapping in a jar file and making a manifest might work once I figure out how to do those things (and if need be re-write a few hundred lines of code). Also I am making progress with getting the JNLP file to work the way I want. Once I get past the certificate issue I will be on a path forward.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: distributing Java apps
     
    Similar Threads
    How to deploy a GUI Swing application?
    How to debug a Jar file
    packaging submission
    executable jar files that contain jar files
    jar file classpath