Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Maven Project loading props file  RSS feed

 
Sloan Bowman
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If this isn't the proper place to post this I apologize however it seems to be maven related so lets give it a try. The issue is as follows. I have a project setup using maven as I have with pretty much all of my projects. Within this project I have standard code to load a props file from a resource stream. The properties file is located in the resources directory and is copied to the target directory as it should be on build. However when I run the project I get FileNotFoundException even though it is in the class path. Is there a trick to getting this to work with maven builds? I'm getting a bit tired of dealing with it. My environment consist of Netbeans 6.1 MavenIDE plugin (3.1.3)and the standard project archetype. Any ideas? I appreciate your time.
 
Peter Johnson
author
Bartender
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From your description, it should be working (provided you did everything correct ;-) ). Have you looked to see if the properties file is packaged in the JAR file? Have you verified that the relative path in the JAR file (or in target/classes) matches the properties file name used in the app? (For example, when I load a properties file located at some/package/my.properties, I use the name "some.pakage.my").

If that does not help you solve the problem, please provide the following:

1) The exact classpath being used for your app (to help in debugging this, it might be best to not run the app from within NetBeans - once you get it running stand-alone you can then work on getting it running in NetBeans)

2) The exact location of the properties file. If you package it in a JAR, then the relative path within the JAR, and an indication of which JAR it is in.

3) The code you are using to load the properties file.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!