• Post Reply Bookmark Topic Watch Topic
  • New Topic

Runnable jar and missing resources.  RSS feed

 
Christoffer Nilsen
Greenhorn
Posts: 18
Eclipse IDE Opera Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, just made my first program where I would like to be able to run it as an runnable jar.
When running the program inside eclipse it all works. However, getting lots of issues with paths when trying to export as runnable jar.
I have issue, tho different issues, on either of the three options:
- Extract required libraries into generated JAR:
- Package required libraries into generated JAR
- Copy required libraries into a sub-folder next to the generated JAR

Currently using "Extract required libraries into generated JAR" because it's the only one which ables me to play sounds and read from file without getting an error.

File structure:

I'm not able to write to file after exporting to runnable jar, on either of the 3 options mentioned above.
Current code getting paths:

Error writing to file:


Would really appreciate any help on the matter.
- Nilsen
 
Les Morgan
Rancher
Posts: 779
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at your error, it says that you are not able to write to your jar file--that's right, if I understand correctly, you cannot write to your jar. When you use getResource in a jar file, your path listed is relative to your jar (inside your jar file).

If you want to write to an external file, rewrite not using get resource.
 
Christoffer Nilsen
Greenhorn
Posts: 18
Eclipse IDE Opera Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Les Morgan wrote:Look at your error, it says that you are not able to write to your jar file--that's right, if I understand correctly, you cannot write to your jar. When you use getResource in a jar file, your path listed is relative to your jar (inside your jar file).

If you want to write to an external file, rewrite not using get resource.

Not sure I fully understand, my usermaps.txt file is stored within my .jar file, under src/main/resources/cfg/, tho maybe my best option would be to write and store information on an external file outside the .jar.
 
Paul Clapham
Sheriff
Posts: 22841
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christoffer Nilsen wrote:Not sure I fully understand, my usermaps.txt file is stored within my .jar file, under src/main/resources/cfg/, tho maybe my best option would be to write and store information on an external file outside the .jar.


Yes, that would be your best option. You can't write into a jar file.

And when you choose to do that, you should write into the user's home directory, or into a subdirectory of that which you create for your application to use. The system property "user.home" will give you the user's home directory.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!