• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

getResource always returns null

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?


 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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).
 
Cindy Carney
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 175
Clojure Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Cindy Carney
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks David!
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Cindy Carney
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, thanks for the clarification, Roels. I appreciate it!
 
Who among you feels worthy enough to be my best friend? Test 1 is to read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic