I am trying to execute a compiled version of my program attachmentUploader.jar
from the command line. This has a number of dependencies on various Java libraries, which I am planning to bundle up with the program and specify as part of the classpath. This package will be moved between environments, and will be executed using the Java runtime for that environment. Using absolute paths for my environment, the command looks like this:
"C:\Program Files\Java\jdk1.6.0_37bin\java" -cp "C:/Users/My Documents/jars/attachmentLoader.jar";"C:\Dev Tools\jxl.jar";"C:\Dev Tools\org.apache.commons.codec";"C:\More Dev Tools\java-json.jar" com.custom.test.postClient
I would like to amend all the classpath jar paths to be relative to where my main class is saved, but I read that relative paths in this situation would be relative to where the Java is executed from. In my case this could be anywhere, as it will depend on where this has been installed. Is there a straightforward way of getting round this?
Thanks all.
答案 0 :(得分:1)
There are actually several ways:
java -jar path\to\jarfile.jar
I recommend you use a standard build tool such as gradle, which has an application plugin generating all those script files for you, for all platforms, and bundles the whole application into a zip or tar.gz file.