Reputation: 1150
I am using javac
to compile a file called Rengine.jar
.
I tried:
javac –classpath ./REngine.jar
javac –cp ./REngine.jar
javac ./REngine.jar
javac –classpath REngine.jar
And here are the errors that I got:
javac: invalid flag: –classpath
Usage: javac <options> <source files>
use -help for a list of possible options
javac: invalid flag: –cp
Usage: javac <options> <source files>
use -help for a list of possible options
javac: invalid flag: ./REngine.jar
Usage: javac <options> <source files>
use -help for a list of possible options
javac: invalid flag: –classpath
Usage: javac <options> <source files>
use -help for a list of possible options
I am not familiar with Java at all and I could not find an answer to this problem with a Google search. I precise that I am in the good directory and that I am using Mac OSX. My Java version is 1.8.0_20. Any advice would be much appreciated! :)
Upvotes: 0
Views: 30090
Reputation: 13
specify the option and source file, try like this:
javac -classpath ./lib/* file.java
in case you have any problem try specifying which artifact the compiler will use:
javac -classpath ./lib/myjar.jar file.java
Upvotes: 0
Reputation: 746
Firstly, you cannot compile a .jar
file. A .jar
file is a collection of complied .java
files (.class
files). You are however able to run a .jar
file if your manifest file is set up correctly.
The procedure is as follws:
Compile:
javac MyClass.java
the above line creates MyClass.class
Create JAR with manifest file:
jar cfe myJar.jar myClass myClass.class
Run JAR:
java -jar myJar.jar
Upvotes: 4
Reputation: 22973
javac - the Java source compiler, will compile the Java source file *.java
into JVM bytecode the class file *.class
To execute a Java program you need to call a class file with java YourClass
.
The Jar file is a Java archive
file. Which contains other files. For example class files. If you want to run a class from within the Jar file there a two way.
executable Jar
java –jar REngine.jar
This depends on the manifest file inside the Jar, which defines the main class which should be executed.
class inside a Jar file
java –cp REngine.jar package.YourClass
This would execute the class package.YourClass
(assuming the class has a main
method).
Upvotes: 1