Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Small .properties problem with multiple platform

 
Pablo Mino
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I've seen this in a couple of post but can't get it to work

My problem is I got a .properties file which is read and written by a .jar app. When I run the project from eclipse I ge the file like this:



But the standard we work here says IF we use a .properties it should be in a /conf folder. so I change that line to this, everytime I require to build it with ant



Turns out that on Linux the "../" is nto working and I already trie all the combinations with // \\\ and anything

I would like in order to avoid the changes and the problems with relative paths, by including the .properties file inside the jar, something like keeping ti next to the src folder on eclipse and that when I build the Ant target it stays at the initial level inside the jar, How?
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When working with JAR files, you can't make any assumptions on what the current directory is, and therefore what relative files will be. Your resources should:
a) be specified using absolute paths, or
b) be put inside the JAR file so you can use Class.getResource(AsStream) or ClassLoader.getResource(AsStream), or
c) be put on the class path, so you can use ClassLoader.getResource(AsStream).
 
Pablo Mino
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I choosed an option d), went for the preferences API, pretty cool thing

I'm using it to pass values between different JPanels as well, I wonder if I'm overusing it

Thanks for the help
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic