I'm developing a tool which will take in an XML file by the user. The tool will perform some manipulation and create a new XML file which then the user can take and do whatever they please with it.
I want to place my jar in a folder (XMLTOOL) alongside user's XML file (input.xml). The hierarchy is as follows:
XMLTOOL
|__tool.jar
|__input.xml
During runtime, I wish to access the file input.xml (or any other XML file the user puts in this folder (e.g. through command line args: java tool newInput.xml
)
Currently I'm using:
ClassName.class.getResource(inFile);
Where ClassName
is the name of my class. However this only works if input.xml
is in the same package as my source files in Eclipse.
So what is the standard convention for structuring resource files in Java projects, keeping in mind that these resources should be accessible when running from a JAR archive.