0

I have a runnable jar-file which I want to start from a batch file. However the jar-file has to be started with a VM-option. The following batch file starts the jar file (in a static way).

java -Djava.security.policy=C:\Users\uname\
\src\main\java\rmi\client.policy 
-Djava.rmi.server.codebase=file://C:/Users/uname/Documents/Folder
/anotherFolder/target/classes/ -jar %~dp0jarfile.jar %*

pause

btw: I know that

\src\main\java\rmi\client.policy

is not in a jar file yet, but I'm assuming that everybody has this file structure already on his machine.

However, I want to be able to start the jar file with a relative path, so that every Windows10 (x64) user can use my jar file system-independently. How to achieve that via batch?

John
  • 33
  • 5

1 Answers1

0

Replace each reference to user home C:\Users\... with %userprofile% variable as per this answer explanation.

java -Djava.security.policy=%userprofile%\src\main\java\rmi\client.policy 
     -Djava.rmi.server.codebase=file://%userprofile%/Documents/Folder/anotherFolder/target/classes/ 
     -jar %~dp0teamFour-1.0-SNAPSHOT.jar %*

or switch to %userprofile% directory with cd before executing java and depend on relative paths.

Karol Dowbecki
  • 43,645
  • 9
  • 78
  • 111