views:

38

answers:

1

Hi,

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!

+1  A: 

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.

Istao
thanks. how do i load them through a resource? i've been trying to use file paths...
Michael Jones
I edit my post to answer. But I think it's not a good way ; it's best to put a config file in the jar (so in the appli and in the classpath), or put it in a local user directory outside the classpath, so to memorize the config path in a preference or in some conventional way.
Istao