Unable to find .properties file at runtime
How do I edit a Run Configuration in IntelliJ so that the classpath includes a .properties file needed at runtime?
The source is setup as follows:
\oratest.iml
\oratest.ipr
\oratest.iws
\Connection.properties
\src\legoland\oracle\oratest\*.java source files
This is a standard Java app and I have setup and Run Configuration to execute main() in one of the classes. When it runs, one of the java classes do this:
private Connection dbConnection() {
// Load the properties file to get the connection information
Properties prop = loadParams("Connection");
...
}
This method tries to connect to an Oracle database. It fails on the first line with a 'resource bundle not found' exception.
I can't work out how to add '.' to the classpath in the Run Configuration so that it will pick up the Connection.properties on the classpath. Or, I if I move the Connection.properties file to where the java files are, how to have IntelliJ copy the .properties file into the .class output folder so that it finds it at runtime there.
Can anyone help?
Thx
Please sign in to leave a comment.
Yeah, that is the common way of doing it.
For properties files you have to do nothing special - they are copied automatically to the output folder.
Specifically which files get copied is configured in Settings -> Project Settings -> Compiler -> Resource patterns
Most of the time I create another folder "resources" where I put all my properties, pngs, ... and configure it as a source root in Idea, so that those files get copied.
That worked nicely.
Created a folder called 'resources' at the top level and moved Connection.properties into it. Went into Module Settings, on 'resources' and clicked the blue 'sources' folder. IntelliJ then copied the .properties file into the 'classes' folder and it picked it up at runtime.
Thanks for your help