Forums Register Login

getResource always returns null

+Pie Number of slices to send: Send
Hi there. I'm preparing my submission for the SCJD, and have stumbled across what so many of you already have, the whole 'must load the resource from the jar' bit.

I got that working for images in a folder, but I couldn't get that working for the database file at the top level of the jar, located outside any package. I finally broke down and used



and managed to locate it, but it felt wrong. I don't know why I couldn't load that file like I did the images - the only difference was, it wasn't in a package.

That brought to light a different error - now it can locate the file, but when it tries to create a new RandomAccessFile from it like this, it fails.



Which makes sense, since I also read you can't modify files in the JAR. But that does leave me with one pressing question: Will the reviewer be extracting the files from the JAR, before testing it? If not, I don't see how I can possibly modify this file.

Any suggestions?


+Pie Number of slices to send: Send
I suggest you use Use Roel's

Submission Jar: test case + Ant build script to build your jar.

to build your jar, it will save you some time and trouble. I think that build.xml file will put your images somewhere in the runme.jar file.


Will the reviewer be extracting the files from the JAR, before testing it?

I do not know.
If you build your jar using Roels build.xml file, then you do not have to worry about that.
There is also a JUnit test that you can use to test the jar file created by Roel's build.xml.
Just search for Submission Jar: test case + Ant build script to build your jar
+Pie Number of slices to send: Send
Hi Cindy,

That's an easy one: your database file is not supposed to be in the jar. Before your client application (standalone mode) or server application starts, the user will have to point to the database file! The database file should NOT be packaged inside the runme.jar; it should be packaged into the submission jar on the path specified by your instructions.

Will the reviewer be extracting the files from the JAR, before testing it?


If I execute java -jar path_to_jar/runme.jar alone the application should run in standalone mode, no extractions of files (inside the runme.jar) should be needed!

Kind regards,
Roel
+Pie Number of slices to send: Send
 

Mxolisi Veco wrote:I suggest you use Use Roel's Submission Jar: test case + Ant build script to build your jar.


Seems an excellent idea to me

Mxolisi Veco wrote:Just search for Submission Jar: test case + Ant build script to build your jar


Or have a look at the ScjdFaq (you can find a topic with link to the appropriate thread).
+Pie Number of slices to send: Send
But in a message you posted here, you stated:

Roel De Nijs wrote:Of course I am sure! And to prove it, here is a (snippet of the) listing of my submission jar created with the jar tool:[code]
C:\Java> jar tf submission.jar
META-INF/
META-INF/MANIFEST.MF
code/
docs/
db-1x1.db
runme.jar
version.txt



That shows the db-1x1.db file inside the submission jar file. Don't forget, we're talking about two jar files here - the 'runme.jar' file, and the submission jar file containing everything. My question is if they extract the contents of the outer jar file first, which would expose the runme.jar and the database at the same level.
+Pie Number of slices to send: Send
The submission jar is just a tote for keeping the disparate parts together. It'll be fully expanded, and the evaluator will then run runme.jar with the appropriate arguments.
+Pie Number of slices to send: Send
Thanks David!
+Pie Number of slices to send: Send
 

Cindy Carney wrote:That shows the db-1x1.db file inside the submission jar file.


Exactly! According to my instructions that was the location I had to put my database file. And of course the submission jar will be extracted, because it is no more than an archive (could be easily a zip) so you can simply submit 1 file instead of hundreds of files.
The runme.jar will not be extracted, should not contain the database file and you should not try to access the database file from a jar at all. The user (evaluator) will point to the file on its filesystem to run your application in different modes.

Kind regards,
Roel
+Pie Number of slices to send: Send
OK, thanks for the clarification, Roels. I appreciate it!
If we don't do the shopping, we won't have anything for dinner. And I've invited this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1592 times.
Similar Threads
how do you load images from a jar file for image buttons?
Class Class
executable jar file
Help - getResource returns null
Loading resources - Jar files
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 16:34:30.