This discussion is archived
1 2 Previous Next 17 Replies Latest reply: Aug 2, 2010 4:33 PM by 793415 RSS

Web Start with local folders included

843804 Newbie
Currently Being Moderated
Hello experts,

I am new to Java Web Start. After two days, I finally got Web Start to work :) The app is deployed and run as expected. But the app cannot find its resources. The app contains some local folders and files such as docs, grids, temp, app.properties, paths.txt. I have all the folders and files jarred in app.jar. app.jar, launch.html, and launch.jnlp are archived in war file and deployed. The app uses common File IO such as File, FileReader, and BufferedReader. Would that work or I have to use JNLP API? I guess my question is - when the app downloaded and run how does it know where to find the folders and files when app.jar is sitting on the web server? Can someone point me to the right direction.

Thank you in advance
btran
  • 1. Re: Web Start with local folders included
    793415 Pro
    Currently Being Moderated
    btran007 wrote:
    ..The app uses common File IO such as File, FileReader, and BufferedReader. Would that work or I have to use JNLP API?
    The answers to both your questions are 'no'. Resources within Jar files are accessed by URL, something like..
    URL urlToResource = this.getClass().getResource("/launch.html");
    InputStream is = urlToResource.openStream();
    InputStreamReader isr = new InputStreamReader(is);
    // ...
    I am not sure from your description if you mean that the main Jar contains other Jars. That will not work. If the app. uses multiple Jars, just add multiple <jar ...> elements in the JNLP.
  • 2. Re: Web Start with local folders included
    843804 Newbie
    Currently Being Moderated
    Thank you for looking into my problem. Sorry I was out the last few days. What confuses me the most about Java Web Start is understanding the mechanic behinds it. I have a perfectly working desktop app with local folders and files which it accesses. Now I want to JAR/WAR and deploy as Web Start because it's dynamic and convenient. Now it is deployed and user clicks on the link to download it and run. I assume that the app is downloaded and installed somewhere on user local machine but that is not the case, just a reference to the jnlp file. Then how does the app access its resources (beside JAR)? I would like to open and update or create new resources. I don't think it's possible. For my problem, I think it's best to zip it up and have user download and unzip the whole app. Unless I totally don't understand Web Start. Someone please response.

    Thanks
    btran
  • 3. Re: Web Start with local folders included
    793415 Pro
    Currently Being Moderated
    btran007 wrote:
    ...I have a perfectly working desktop app with local folders and files which it accesses. Now I want to JAR/WAR and deploy as Web Start because it's dynamic and convenient. Now it is deployed and user clicks on the link to download it and run. I assume that the app is downloaded and installed somewhere on user local machine but that is not the case, just a reference to the jnlp file.
    Your analysis is wrong. All the resources in Jars listied in the resource section of the JNLP file are cached on the local machine. I could tell you, as the administrator of your own machine, how to find them.

    However that will not do your application any good. Sun decided that an application had no business knowing that location, so instead of returning the local (cached) address from the call to getResource(), it shows the address back on the site. Under the covers, the JRE will check the local cache.
    ..Then how does the app access its resources (beside JAR)? I would like to open and update or create new resources.
    Opening we have covered. Updating or creating is more tricky.
    ..I don't think it's possible. ..
    You seem to think a lot of things that are wrong. What is the nature of the things you wish to 'update or create'? Be as clear & specific as possible. I need to know the size and general nature of these resources.
    ..Someone please response.
    Odd words, coming from someone who took 3&1/2 days to reply to the first response. ;)
  • 4. Re: Web Start with local folders included
    843804 Newbie
    Currently Being Moderated
    Andrew,

    Again, many thanks. I do sound very desperate, don't I :) Here is the structure of the app. The app folder contains app.jar, app.properties, paths.txt, stderr.txt, stdout.txt, /doc, /grids, /lib, /META-INF. app.properties is read first upon load. paths.txt is updated anytime by user(s). stderr.txt and stdout.txt are created for standard errors and outputs (this can be on local machine). /docs are just user manual in pdf and html. /grids are grid files used as inputs. Hope that is clear.

    Thanks
    btran
  • 5. Re: Web Start with local folders included
    793415 Pro
    Currently Being Moderated
    btran007 wrote:
    ..The app folder contains app.jar, app.properties, paths.txt, stderr.txt, stdout.txt, /doc, /grids, /lib, /META-INF.
    This is a bit confusing. Why does a 'folder' (or directory as it is more commonly known across systems) contain a /META-INF directory? What is inside that directory?

    What does /lib contain - natives, other Jar files?
    ..app.properties is read first upon load. paths.txt is updated anytime by user(s). stderr.txt and stdout.txt are created for standard errors and outputs (this can be on local machine). /docs ..
    /docs or /doc? Accuracy is important in programing. Even more important when seeking help over the web on international forums.
    ..are just user manual in pdf and html. /grids are grid files used as inputs. ...
    Put the app.properties into the Jar.

    The default paths.txt should be in that Jar as well. If it is changed, put it into the JWS PersistenceService. If you go to use the information check the PS first, if it is not there, use the paths.txt. Here is a small [demo. of the PersistenceService|http://pscode.org/jws/api.html#ps] *(<- link).*

    Is your app. trusted or sand-boxed? I'll answer further questions when you have filled in answers to each of my questions.
    ---------------------
    Note that going from a raw application to one launched by JWS can be a PITA for developers. It requires rethinking some aspects of how things are done. On the other hand it is well worth the effort given how easy it is for the end user.
  • 6. Re: Web Start with local folders included
    843804 Newbie
    Currently Being Moderated
    Andrew,

    I took your advice and have everything in the jar file. Now it seems to work because getClass().getResource() only work with files and directories in the jar file. However, is it possible to have /doc and /grids outside of jar? I want them separate in case we update user manual or adding new grid files without having to re-deploy the app.

    Regarding JWS PersistenceService, it only writes to user cache but does not update or allow adding new files on the web server so they can be shared.

    Again, thanks for all your help and contribution.

    btran
  • 7. Re: Web Start with local folders included
    793415 Pro
    Currently Being Moderated
    btran007 wrote:
    ..I took your advice and have everything in the jar file. ..
    Oops! I meant a+ Jar file. My bad. But then, it is listed in the 'resources' section of the JNLP, not the 'resource' section. ;)
    ..Now it seems to work because getClass().getResource() only work with files and directories in the jar file. However, is it possible to have /doc and /grids outside of jar?..
    You can put them in doc.jar and grids.jar. JWS will check all Jars against the times of the Jars on the server and download only the ones that are newer than the local copies. Automatic update is one of the key selling features of JWS.

    Even better, code and resources can be broken up further by package, so if the grids data were split into linear/ & logarithmic/ each could be in a separate Jar, minimizing the download for the end user if just one is changed.
    ..adding new files on the web server so they can be shared.
    Umm.. OK. How does your..
    ..perfectly working desktop app ..
    ..do it?

    I ask this because:
    a) This is the first I am aware that this application has to upload data to the server, thereafter sharing it between users.
    b) It can be done in exactly the same way in a sand-boxed JWS application, as it is done in your 'perfectly working desktop app'.

    Note also that:
    a) This topic is veering far away from 'Web Start with local folders included'
    b) I am no expert in server-side development (for arranging the upload/file sharing) or the security required for that.

    Perhaps if you are having problems with uploading and file sharing you should start that on one of the [server side forums|http://forums.sun.com/category.jspa?categoryID=20] (with no mention of web start).
  • 8. Re: Web Start with local folders included
    843804 Newbie
    Currently Being Moderated
    Andrew,

    You're right. I am having things mixed up. As far as JWS, I am better now thanks to you.

    Thank you much!
    btran
  • 9. Re: Web Start with local folders included
    793415 Pro
    Currently Being Moderated
    btran007 wrote:
    ..As far as JWS, I am better now thanks to you.
    Excellent. If any further JWS related questions pop up, feel free to ask them on the JNLP/JWS forum.
    Thank you much!
    You are welcome.
  • 10. Re: Web Start with local folders included
    843804 Newbie
    Currently Being Moderated
    Andrew,

    I need to disturb you again. I finally got JWS to work, but not quite. It runs fine when launched from IE but not Firefox. The app cannot read or create resources (files). The files being read are included in the JAR file and stderr.txt and stdout.txt are created on user's desktop at load time. However, if a user with local admin rights on their machine can launch the app from Firefox with no problems. I asked System Admin for help but they don't have a solution. It has to do with permission. But why it works in IE but not Firefox?

    Thanks
    btran
  • 11. Re: Web Start with local folders included
    793415 Pro
    Currently Being Moderated
    btran007 wrote:
    ..The app cannot read or create resources (files)...
    ..why it works in IE but not Firefox?
    It is odd you should ask that. Read this thread [http://forums.sun.com/thread.jspa?threadID=5446028]. It shows the same symptoms as what you describe.
  • 12. Re: Web Start with local folders included
    843804 Newbie
    Currently Being Moderated
    Andrew,

    I found one thing peculiar how the way Firefox and IE create files on local machine. This app, when open in IE the files are created on user's desktop. However, Firefox create the files under c:\program files\mozilla firefox. Because I don't have write permission to the directory the application bombs. I need to modify the file location but I am afraid of hard coding. I am not sure how that is done when user may run on PC, MAC, UNIX, Linux, etc...sigh!

    btran
  • 13. Re: Web Start with local folders included
    793415 Pro
    Currently Being Moderated
    btran007 wrote:
    ..I found one thing peculiar how the way Firefox and IE create files on local machine. This app, when open in IE the files are created on user's desktop. However, Firefox create the files under c:\program files\mozilla firefox. Because I don't have write permission to the directory the application bombs. I need to modify the file location but I am afraid of hard coding.
    Oh ..right. In that case, do not create files with either no path or a hard coded path that comes from you. Use ..
    System.getProperty("user.home")
    ..as the initial path and preferably put them in a sub-directory.

    If you can write anywhere on the user's machine, it will be there.
  • 14. Re: Web Start with local folders included
    843804 Newbie
    Currently Being Moderated
    Thanks for the suggestion. I will definitely use that.

    btran
1 2 Previous Next