+ 2
how to create .jar file?
I have a java code ready, but I don't know to invoke without using IDE. help pls.
5 Réponses
+ 6
To execute your Java code there is no need to generate a jar file from it. You can compile them using the javac executable and then you can execute your code using java. You have to set classpath (where compiled classes are) and the class to be executed (it must contain the main method). For example:
java -classpath c:\mycode\classes mypackage.Main
On Linux you have to set classpath in different way than on Windows.
But to answer the question, you can create a jar file this way:
jar cvf myjar.jar *.class
If you want to be able to execute jar via:
java -jar myjar.jar
then you have to add a manifest to the jar which describes which class should be executed.
See documentation for details.
+ 4
It was java, not javac I guess. You set classpath wrong or you really don't have class. We should see it to help. What is your class name? Do you use a package? Do you have compiled class file next to the java file? Where they are located on your disk? What is the command you executed? What platform do you use? Does your class contains valid main method?
There are a lot of chance to fail :)
+ 1
I tried executing my java program using javac executable, but getting an error "Error: Could not find or load main class first"
+ 1
My classpath was misspelled, it works now. Thanks a lot.
- 1
yeah,