I\'m trying to load a jar using
@echo off
java -jar Test.jar
pause
With the manifest of
Manifest-Version: 1.0
Main-Class:
I was getting this error because my main class is in test package, and I am creating artifact using IntelliJ. After I checked the box Include Tests when creating artifact, it got resolved.
Screenshot from IntelliJ showing Include Tests checkbox
1.Create a text file calles Manifest.txt and provide the value as
Main-Class: classes.TestClass
2.Create the jar as
jar cfm test.jar Manifest.txt classes/*.class
3.Run the jar as
java -jar test.jar
I follow the following instruction to create a executable .jar in Eclipse. Then Run command "java -jar .jar " to launch the program.
It takes care of creating mainfest and includeing main class and library files parts for you.
http://java67.blogspot.com/2014/04/how-to-make-executable-jar-file-in-Java-Eclipse.html
in IntelliJ, I get this error when trying to add the lib folder from the main project folder to an artifact.
Placing and using the lib folder in the src folder works.
At least the way I've done this is as follows:
If you have a nested src tree (say com.test.myclass.MyClass) and you are compiling from a root directory you need to do the following:
1) when you create the jar (usually put this in a script): jar -cvfm my.jar com/test/myclass/manifest.txt com/test/myclass/MyClass.class
2) The manifest should look like:
Mainfest-version: 1.0 Main-Class: com.test.myclass.MyClass Class-Path: . my.jar
3) Now you can run the jar from anywhere like this:
java -jar my.jar
Hope this helps someone
I had this error because I extracted JAR files from libraries to the target JAR by IntellijIDEA. When I choose another option "copy to the output directory...", it solved the problem. Hope this helps you