Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Runnable jar and missing resources.

 
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
 
Rancher
Posts: 904
22
Netbeans IDE Oracle MySQL Database Tomcat Server C++ Java
  • 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.
 
Marshal
Posts: 25835
69
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.
 
I think she's lovely. It's this tiny ad that called her crazy:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic