I am using Intellij IDEA 12.0.4 on MAC OS X 10.8.3 to create a jar file.
I go to File -> Project Structure -> Artifacts -> + -> Jar -> From modules with dependencies -> Selected Main Class after browsing -> selected extract to the target jar -> Directory for META-INF automatically gets populated -> OK -> Apply -> OK -> Build -> Build Artifacts -> Build
Now If I try to run jar using:
java -jar path_to_jar/jar_file
I get this error
no main manifest attribute, in path_to_jar/jar_file
$ java -version
java version "1.7.0_17"
Java(TM) SE Runtime Environment (build 1.7.0_17-b02)
Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)
Any pointers, what I am doing wrong?
To fix this issue do two things:
move META-INF in to src/main/resources
then: file-> open module settings
choose artifacts, remove your current one and create a new one, but this time, instead of choosing "extract to the target jar", choose "copy to the output directory and link via manifest"
for the path to META-INF, put the path of the resources dir above that you copied META-INF in to..
now build your artifact
im terminal, go to dir where jars have been produced and to run do:
java -jar yourjarfile.jar
have fun
In my case, it was because IntelliJ was extracting all the dependencies into the output jar, which ended up overwriting the /META-INF/MANIFEST.MF
file with something from one of my included dependencies.
I had to open up the jar and copy in the real MANIFEST.MF
from the location indicated in the "Manifest File" property that is automatically set in that artifacts page under Project Structure".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With