Reputation: 97
I'm trying to refer to a properties file in my NetBeans project using Maven.
While developing, I used the following code:
MyClass.loadProperties("src/main/resources/neo4j.properties");
This worked fine.
Now that I've just built my project to a JAR, when I execute it, it complains that it can't find this file.
I don't want the file to be in the JAR file - I'd really just like to be able to specify a location to load the properties file from - probably the same directory as the main JAR.
What path should I use? In fact, I'm not clear on how this works at all - I ran into a similar issue with a previous project.
I think the src/main/resources is specific to Maven isn't it? When a JAR is running, are all directories relative to the one in which the JAR is located?
Help!
Upvotes: 1
Views: 762
Reputation: 7585
I don't know what is this MyClass.loadProperties method ?
Yes, the src/main/resources is a maven convention to put resources, see Introduction to the Standard Directory Layout.
So the files in this directory are in the app jar. You get them throw a resource protocol, not a file protocol.
If you want some config files in another place, and not in a jar, you need to construct a policy yourself. For instance in the home directory, in a user choice folder, on the net, in a directory on the classpath, in a preference thing...
edit : To get a config file in a local directory throw a resource thing, you need to put this directory in the classpath.
Upvotes: 2