Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java -jar

 
Fernando Matias Valadao
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, buddies!
I've packaged my Java app into a runnable jar file, which beyound the .class files also include a "conf/conf.properties".
Therefore, my app.jar looks like this:

com/enterprise/*.class
META-INF/MANIFEST.MF
conf/conf.properties

The problem is that my app runnable class can't find the "conf/conf.properties". The error is "The system cannot find the path specified".

If I take it out and put it in a directory ("conf/conf.properties"), everything works just fine.

Does it mean I have to put the conf/conf.properties outside the .jar file? Or am I doing some kind of ?
Thanks in advance.

Fernando
 
Arnaud Burlet
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello there,

the last time I needed something like that, I used that piece of code :


Can't remember another way ... hope that one is ok for you !
Arnaud
 
Fernando Matias Valadao
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for replying, Arnaud, but are you sure it works?
I have tried it the way you posted but the input stream is empty.
Do you have any idea why this is happening?

Fernando
 
Fernando Matias Valadao
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Arnaud!
It worked!!! I did it this way:

...
InputStream configStream = ClassLoader.getSystemClassLoader().getResourceAsStream("conf/conf.properties");
Properties confFile = new Properties();
try {
confFile.load(configStream);
...

Thank you very much!


Fernando
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic