aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Reading the DB file from the runme.jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Reading the DB file from the runme.jar" Watch "Reading the DB file from the runme.jar" New topic
Author

Reading the DB file from the runme.jar

David Sham
Ranch Hand

Joined: Apr 19, 2005
Posts: 61
I am getting close to submission and have come across a problem. After jarring up my project, how can I read and write to the database file in the runme.jar? I understand that you cannot write to a flat file that is in a jar file. I'm using a RandomAccessFile for all of my file IO to the database file, so my raf does not work with an InputStream.

My db file is in the root directory of my runme.jar. Whenever I do a ClassLoader.getSystemResource("dbFileName");, it returns a null URL.

Any ideas??? Or are we only supposed to include the supplied db file with the runme.jar expecting the examiner to just extract the db file to hard disk and then access it through our application? I'm really not clear on what to do here.

Any input is greatly appreciated!!! Thanks.
Wei-ju Wu
Ranch Hand

Joined: Feb 16, 2005
Posts: 147
The db file is not supposed to be in the runme.jar. It should be in your jar file which wraps up the code, the documentation, the runme.jar and the foobar.db file.
The runme.jar file contains your compiled classes and your manifest file which indicates your starting class.


"The UrlyBird catches the certificate. And he's gonna FlyByNight"<br /> <br />SCJP 1.2/5.0, SCJD, SCBCD, SCWCD, SCEA
David Sham
Ranch Hand

Joined: Apr 19, 2005
Posts: 61
OK, so the runme.jar is part of the contents of the single submission jar file we upload?? Is that right?

Then how will the examiner read the db file? Will he extract it from the submission jar first, and then run the runme.jar? Somehow the examiner must be able to select a db file from the startup dialog that appears when the runme.jar is run. He can only do this if he has copied the submitted db file to his hard disk. Am I missing something here, or is this how it should be???

Also, how is the examiner supposed to read the userguide doc? My project opens the userguide from the application. Can I assume that the examiner will extract the userguide html files to the current working directory and access them from there?

I'm really not clear on this and just want to make sure I understand how to configure all of this. I don't want to get an auto-failure for some stupid mistake due to a misunderstanding of the instructions.

Thanks again for any input!!!
Wei-ju Wu
Ranch Hand

Joined: Feb 16, 2005
Posts: 147
Hi David,


OK, so the runme.jar is part of the contents of the single submission jar file we upload?? Is that right?


yes.


Then how will the examiner read the db file? Will he extract it from the submission jar first, and then run the runme.jar? Somehow the examiner must be able to select a db file from the startup dialog that appears when the runme.jar is run. He can only do this if he has copied the submitted db file to his hard disk. Am I missing something here, or is this how it should be???

Also, how is the examiner supposed to read the userguide doc? My project opens the userguide from the application. Can I assume that the examiner will extract the userguide html files to the current working directory and access them from there?


The specification tells you the exact structure of the deliverables which is the structure that you will also get if you extract your submission jar file.
If everybody follows this structure, the examiner will always find the same structure after unpacking the submission jar (e.g. with jar xvf scjda-xxxxx.jar).

I had the URLyBird 1.1.3 assignment. In the application, the user needs to specify the configuration at startup time, my implementation allows for specification of the file location in the configuration dialog.

So what you can assume is the directory structure that is specified in your assignment.
David Sham
Ranch Hand

Joined: Apr 19, 2005
Posts: 61
Therefore, the examiner will first extract the single submission jar before running the runme.jar. I guess he would have to, to get to the runme.jar.

So I should put the db file at the root level of the submission jar. That seems to be what my instructions indicate. The userguide html files will go under the "docs" directory from the root of the submission jar.

This means that the examiner can extract the submission jar into whatever directory he is currently in (the current working directory). So, I should make sure my userguide html files look in the current working directory to show the help doc. The examiner will also be able to browse to the db file in the current working directory after extracting the submission jar and launching the application startup dialog. I should even be able to look in the current working directory first for the db file. If it is there, then put it in the startup dialog.

Does that sound right??

Thanks again!
Wei-ju Wu
Ranch Hand

Joined: Feb 16, 2005
Posts: 147

So I should put the db file at the root level of the submission jar. That seems to be what my instructions indicate. The userguide html files will go under the "docs" directory from the root of the submission jar.


that's what my specification is saying too, but if you have your docs online the specification (at least for my assignment) does not require you to put the user docs under "docs". If you have online documentation, by placing it in the runme.jar file you would be on the safe side.

I chose the "lazy" solution and did not provide online help.
By placing the userguide.html into docs you can simply place the related data relative to it and refer to it by relative url's and it would always work within your browser (usually has nicer output, too ).


The examiner will also be able to browse to the db file in the current working directory after extracting the submission jar and launching the application startup dialog. I should even be able to look in the current working directory first for the db file. If it is there, then put it in the startup dialog.

Does that sound right??


you could do that (looking up the db file of course), which would mean you assume a fixed filename to look for (I would not consider it a bad idea). By letting the user select the file he could also select whatever file he wants to use (if the file is consistent with the specification of course).
Frans Janssen
Ranch Hand

Joined: Dec 29, 2004
Posts: 357
userguide html files will go under the "docs" directory from the root of the submission jar.

Hi David,

To be on the safe side, I would not assume that the html files will be at a specific location relative to the runme.jar or the current directory. If you have on-line help, I would advise you to put the help files inside the runme.jar. You can then access them using the ClassLoader.getResource() method.

Frans.
[ May 09, 2005: Message edited by: Frans Janssen ]

SCJP 1.4, SCJD
David Sham
Ranch Hand

Joined: Apr 19, 2005
Posts: 61
I chose the "lazy" solution and did not provide online help.
By placing the userguide.html into docs you can simply place the related data relative to it and refer to it by relative url's and it would always work within your browser (usually has nicer output, too ).

I also chose this approach. My application accesses the html files from a help menu option and then displays them in a JTextPane. By "relative url's" do you mean the following: currentWorkingDirectory\docs\htmlFile.html, where the currentWorkingDirectory can be anything? Therefore, the html files under the docs folder would be "relative" to the currentWorkingDirectory. Is that right?

I'm not very adept at this packaging stuff. Thanks!
Wei-ju Wu
Ranch Hand

Joined: Feb 16, 2005
Posts: 147
Hm, from what you say it seems that you have online help, which means that you have a help system within your application. In this case you should better package it your jar file (the solution also suggested by Frans).

The "lazy" approach that I mean is simply opening the file userguide.html in your browser
Lara McCarver
Ranch Hand

Joined: Dec 09, 2003
Posts: 118
I happen to have this book

Java 2 Sun Certified Programmer and Developer by Kathy Sierra and Bert Bates

I bought it when I was studying for SCJP a long time ago. I personally don't see that much useful stuff in here for SCJD **EXCEPT** there is a picture that shows where everything is supposed to go, i.e. the file structure of what you are supposed to submit for SCJD. It is in one of the last chapters. I think not everything is 100% accurate, for example it shows a file "db.db" in the same folder as runme.jar (all pacakaged up within another jar) but the database file I got is called "db-2x3.db" or something like that, so that is what I am going with. Even so, it is immensely helpful for figuring out what you are supposed to deliver.
David Sham
Ranch Hand

Joined: Apr 19, 2005
Posts: 61
You mean you can just put the html files in the jar and leave them there for the examiner to open in a browser manually? That's acceptable?? I may opt for that approach except I've already done all the work to make my html files accessable from my application. So if that is what is meant by "online help" then that is what I have. I thought "online help" meant that your help files were on the Internet.

So if I can access my html files from
ClassLoader.getResource(String name); with the html files in the runme.jar then there should be no problem, right?

So am I correct in understanding that the examiner will be extracting the database file first, and then using it from wherever he extracted it to?

Thanks everyone for your patience and input!!!
Wei-ju Wu
Ranch Hand

Joined: Feb 16, 2005
Posts: 147
No, there are two ways to provide user documentation:

1. in the docs directory
2. online, reading it from within your application and viewing it in the EditorPane.

As far as my understanding is, that you are doing approach 2, which is called "online help" (in the beginning I also thought that online help meant on a webserver, by the way - but it means within the application)


So if I can access my html files from
ClassLoader.getResource(String name); with the html files in the runme.jar then there should be no problem, right?


Yes.


So am I correct in understanding that the examiner will be extracting the database file first, and then using it from wherever he extracted it to?


I could imagine that she/he will simply extract the tree structure that you jarred as a whole and reviews the structure that she/he will see after doing so. If the database file is in the root of your tree (if it was specified so), the reviewer is likely to use it from there. But as you provide the option to select it, the reviewer/user has the flexibility to choose whatever database file she/he is using for testing.
David Sham
Ranch Hand

Joined: Apr 19, 2005
Posts: 61
I understand now that I do not need to worry about the location of the database file, as long as it is in the proper location within the submission jar (and it does not belong in the rumme.jar).

I understand that I can put my html userguide files in the runme.jar (and also in the docs directory of the submission jar). This will enable me to use online help from within my application.

Sorry for my stupidity, but thank you Wei-Ju and everyone for your patience and replies!! Much appreciated!!!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Reading the DB file from the runme.jar