I have a jar file which I do not have the source code but want to use.
The jar file prompts for a file to read and generates an output file using a combinatin of the input file and a number of ‘helper’ files it uses for data. It works perfecty fine if run from its expected home directory, but I’m trying to write a script which will allow running the jar from anywhere.
The problem is that if I try running the jar file from anywhere other then its home directories it fails to find the support files it needs to properly generate its data.
If I run the file from its expected home directory I have to give the full address of the input file or it won’t find it. I would prefer to be able to give just the relative path and Java know to look at whatever directory the person calling my script is in.
Is there a way I can have a bash script pass a command line argument to Java that would ensure that this jar looks at both of the relevant directories (directory of the helper files and the current dir of the person calling the script) when trying to resolve a relative file path? Something like the -classpath argument?
With the
--classpath(or-cp) you can tell your Java program where it should take the dependency classes. So, probably if you do like in your files directorythen it will wind the program, and find your files as well.
UPDATE
If it doesn’t work, you can try to force the file loading some other way. The Javadoc says:
So, you can try running the program from the original directory this way:
UPDATE2:
As I wrote in a comment, you can try
symlinks. Execute the following commands in the original directory: