I'm almost finished with my assignment and yesterday I came with an issue, regarding the "suncertify.properties" and the documentation which is available to the user inside the system. The application when launched through eclipse is running as it supposed, it checks the "suncertify.properties" for stored specification and the user documentation is loaded whenever the user requests it. I exported the jar file and the "suncertify.properties" file is in the root file but instead of reading that file it creates a new "suncertify.properties" file in the same directory that the jar relies. This is the code that reads successfully on development but not on production[jar]
Why on earth does it behaves like this and it does not use the existing file inside the jar ?
My second issue is again regarding file so that's why I include in the same section. For the application I developed uer quidance is provided through out the varius screens of the system. All user documentation is placed within a package with the following structure: /client/documentation
During development I ecountered many issues while trying to access files in that directory from "/client/swing/components" and came up with the following solution which is working on development but not on production
This "cheat" is working but not when the application is executed from within the jar. I tried the following solution but again I'm not able to read the file.
I've tried to modify the first line with the followings but again it can't read the file
FileInputStream fis = new FileInputStream("/client/documentation/"+fileName+ ".uig");
FileInputStream fis = new FileInputStream("client/documentation/"+fileName+ ".uig");
FileInputStream fis = new FileInputStream("client.documentation."+fileName+ ".uig");
FileInputStream fis = new FileInputStream("/client.documentation."+fileName+ ".uig");
Your programs must not require use of command line arguments other than the single mode flag, which must be supported. Your programs must not require use of command line property specifications. All configuration must be done via a GUI, and must be persistent between runs of the program. Such configuration information must be stored in a file called suncertify.properties which must be located in the current working directory.
When it sais "must be located in the current working directory" i suppose that it means inside the jar because if the current working directory is the directory from where the runme.jar is executed then my first issue is solved.
The working directory can be retrieved with this code:
You should not package the suncertify.properties file in your submission jar, nor the runme.jar. At first run it will be created (with some default values for example). Consecutive runs will then read that newly created file. That's how I implemented it.
Regarding your second query: I didn't add user documentation in my application because that's extra complexity which is not required. A userguide txt file is much easier. But I think your main problem is how to retrieve a file from a class, so here you can find some info about loading property and configuration files in Java. Maybe it is helpful to you.
I resolved my first issue, I missunderstood my requirements and thought that actually my "suncertify.property" file should be placed on the root folder inside the jar. I'm looking how it is possible to read the user guidance files inside the jar and i'm ready to submit
Joined: Sep 09, 2009
I have taken out the documentation from the source folder. Furthermore in my instruction it specifies the following :
A directory called docs, containing the following items at the top level:
User documentation for the database server and the gui client. If your user documentation is online then you may omit this file. However, if the documentation is not online, you must provide either a single plain ASCII (not word processor format) text document, which must be called userguide.txt, or multiple HTML files which must all be accessible from a starting point document that must be called userguide.html.
Since my user-guidance is online (built-in the application) i created a new folder "online-guide" and placed the help files for each screen there, i deployed the jar, executed the application and user guide is working now from the application.
Since all of these are going to be packaged in one jar, submision, i suppose that the submission jar will be extracted when it comes to evaluate my application otherwise it was pointless to remove the documentation and place it within the submission jar which holds all of the submision parts.
Any insights on this?
The submission jar consists of the executable jar (runme.jar), docs, code, version.txt and the "original" database file. Sun examiners extract the submission jar before running the app.
About your help, you say built-in to the app as in you got a help menu item and pop up a window with the help contents? The userguide stuff can be online or offline or in-app. Online is accessible using "http://...."; offiline is just from the docs directory and in-app is what I have described earlier. Of course if in-app then you need to have those files inside runme.jar file.
My user guidance is supported within the application. I don't have a menu "HELP" but there is help available throughout the application lifecycle. Each view has a generic function which locates its help file and present it to the user. I don't how you implemented your's user guidance but I didn't want to include large pieces of Strings in my code. If i include them inside the jar then I can't access those file. If you have used files to read the user guidance and placed them inside your runme.jar how did you accessed them from your application?
Nicolas Kal wrote:If you have used files to read the user guidance and placed them inside your runme.jar how did you accessed them from your application?
Ah I remember trying that when I did my assignment and I recall you need to use ClassLoader.getResourceAsStream stuff. Of course I ended up just provided offline because I recall I wasn't able to do something with it. Oh and the path of those files (eg inside some package or at the root of the jar) makes retrieving the files tricky.
Joined: Sep 09, 2009
Finally my problems are solved!
I managed to access and read the files within the jar file and not in the same package with the classes or the root folder. I supply the code
InputStream in = ClassLoader.getSystemResourceAsStream("client/docs/"+getController().getClass().getSuperclass().getSimpleName()+ ".uig");
Now when you run on production you have to set the set the class path to you jar file
Then all i have to do is run my application and user guidance is fully working! Thanks for your assistance and good luck to all of us who haven't submitted !
Not sure if setting the classpath is good when you submit. Would Sun examiners actually set their classpath before running your program? Besides you can't have -cp flag when running app - just simply "java -jar runme.jar <parm>".
And if they can't run your app from the getgo ... you fail. So you have been warned.
You are providing context-sensitive help and I think the hardest part is the one you are having trouble with at this moment: localizing your help files through getResourceAsStream (and other similar methods). If I were you I would just skip all this and just make a userguide.txt (or userguide.html if you want some images to be added). It's very easy, you don't have any issues with this approach and you don't lose any valuable time.
Maybe you can have a look at the sources of JavaHelp, some api to add context-sensitive help. Maybe you can find a method to read your help files in a consistent way.
Your programs must not require use of command line arguments other than the single mode flag, which must be supported. Your programs must not require use of command line property specifications.
So your workaround conflicts with a must, which could mean automatic failure...
Joined: Sep 09, 2009
I moved the runme.jar to my D: driver (not c: where it was) and there the classpath is not set. I didn't set the classpath to "D:runme.jar" just run the application and it loaded without any errors and the user guidance is loaded. I'm almost finished i'd rather not change it in the last minute, i'm also looking at tutorial at how you can modify the MANIFEST and introduce there properties but since it is working without having to set the classpath i'll stay with this approach.