I want to run a jar file in a specific directory without moving to this directory.
I mean what will work is
cd /path/to/directory
java -jar <file>.jar
I tried it with -Duser.dir
and later additionally with -Djava.class.path
java -Duser.dir=/path/to/directory -jar <file>.jar
Error: Unable to access jarfile Pepper_ConciergeShort.jar
So if I try it with
java -Duser.dir=/path/to/directory -jar /path/to/directory/<file>.jar
I will receive
java.io.FileNotFoundException: ./concierge.conf (No such file or directory)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:93)
at java.io.FileReader.<init>(FileReader.java:58)
Then I tried it again with -Djava.class.path=/path/to/directory
. Did not help. I will receive the following error.
So again, if I run inside /path/to/directory
my jar file it works. If not, I have problems to read files in this directory.
CodePudding user response:
The -jar directive won't work for you. Specify the full classpath to all your jars, including your own app-jar. Then also specify the class there your main method is located.
CodePudding user response:
How about
java -jar /path/to/directory/<file>.jar