The easiest option is to make the jar excutable using chmod +x compiler.jar
. Then you can run it from your PATH
as follows:
compiler.jar --help
These are a couple of other options to use the java
command to run the file.
Java uses the CLASSPATH to find classes and other resources. The classpath can contain jars and directories. Java will search the classpath for resources. Define an environment variable containing the path(s) you want searched. The path seperator is ; on Windows and : on most other systems. This will work for classes on the command line, but not jars. If you read the manifest
of compiler.jar
you can write a short Compiler
class which invokes the main class. Alternatively, just invoke the main class directly as specifed in the manifest instead of Compiler
(as specified below).
You may already have a classpath defined. Try echo $CLASSPATH
to see if it is. Try
export CLASSPATH=$CLASSPATH:/opt/ClosureCompiler:/opt/ClosureCompiler/compiler.jar
java Compiler
or for closure (other jars will have a different main class).
export CLASSPATH=$CLASSPATH:/opt/ClosureCompiler/compiler.jar
java com.google.javascript.jscomp.CommandLineRunner
You should define your CLASSPATH
where you added /opt/ClosureCompiler
to your path. You don't need it /opt/ClosureCompiler
in your path.
This is a sample Compiler.java file.
import com.google.javascript.jscomp.CommandLineRunner;
public class Compiler {
public static void main (String[] args) {
CommandLineRunner.main( args );
}
}
It can be compiled with the command javac -cp compiler.jar Compiler.java
.