1
votes

I have compiled my java project in netbeans with multiple libraries and it's told me to execute the jar with the following parameters:

java -cp "D:\Documents\proj\lib\commons-net-3.1.jar;D:\Documents\proj\lib\org.eclipse.swt-3.1.jar;D:\Documents\proj\lib\prompt.jar;D:\Documents\proj\lib\zip4j_1.3.2.jar;D:\Documents\proj\dist\Myprogram.jar" pack.Myprogram_GUI

but if I move the folder or try to use this on another computer without the exact same path the program wont load and nor will the libraries. So is there a way to define a kind of root folder? so instead of typing D:\Documents\proj\lib\commons-net-3.1.jar I could just type lib\commons-net-3.1.jar?

2

2 Answers

1
votes

If using Java 6 or later, classpath wildcards are a part of the JVM. You can use relative path using

java -cp ".;.\lib\*" pack.Myprogram_GUI
1
votes

Yes, you can create $PROJECT_HOME as a system environment variable and use it with the path:

java -cp "$PROJECT_HOME\lib\commons-net-3.1.jar;$PROJECT_HOME\lib\org.eclipse.swt-3.1.jar;...