Run a .jar file using .sh file in unix Run a .jar file using .sh file in unix unix unix

Run a .jar file using .sh file in unix


In your shell script change into the directory containing the jar files. Possibly not the best practice but I use this all the time to emulate a 'working directory' where scripts are started from. This way my shell script can be installed in a scripts directory and my Java can be installed in a lib directory.

Assuming your environment is the same when you execute the script as when you call the java from the command line.

#!/bin/shcd /home/applvis/Java/UAT/libjava -jar DirectoryScanner.jar


Depending on the tool you used to generate the JAR, it may have replaced your main class with something else that f.e. sets up the classpath and then calls your class. This happens a lot when generating fat JARs with all the dependencies. Do check the contents of the JAR, as it may contain other JARs in turn.