I had the same problem.
Make sure your MANIFEST.MF is in:
src/main/resources/META_INF/
NOT
src/main/java/META_INF/
Question
I'm trying to package a project using OptaPlanner 6.0.1 libraries into a .jar through IntelliJ IDEA's jar artifact but instead of my manifest.mf containing the standard
Manifest-Version: 1.0
Main-Class: a.b.c.app
the jar uses the one supplied in ecj-3.7.2.jar, one of OptaPlanner's supporting libraries:
Manifest-Version: 1.0
Build-Jdk: 1.6.0_26
Built-By: ibrandt
Created-By: Apache Maven
Archiver-Version: Plexus Archiver
Because of this, a "no main manifest attribute, in appname.jar"
error happens when trying to run the app. If I manually replace the manifest in .jar file with mine everything works correctly. Is there anything I can do to fix this?
I keep the libraries in a separate /lib directory and they were added to the root of jar artifact as Extracted Directory, IntelliJ IDEA is v13.0.1.
La solution
I had the same problem.
Make sure your MANIFEST.MF is in:
src/main/resources/META_INF/
NOT
src/main/java/META_INF/
Autres conseils
To fix:
As noted in @grudolf's comment in one of the other answers, one way to do this (and the only one that worked for me in an imported Gradle project) is to create an empty jar as follows:
This is definitely a bug in Idea. This linked answer works reliably when there are extracted directories. In essence, you find your .idea/JARNAME.xml, add add the following element to the very top of the <root>
element for your jar. Any extracted elements above your new file-copy that contain a manifest will clobber your new manifest.
<element id="directory" name="/META-INF">
<element id="file-copy" path="$PROJECT_DIR$/modulename/src/META-INF/MANIFEST.MF" />
</element>
If you want to specify Main Class, you have to add this plugin to pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifest>
<mainClass>Form</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
I had a similar problem.
The problem was in file pom.xml.
<archive>
<manifestEntries>
<Dependencies>one.jar,
two.rar,
other.jar
</Dependencies>
</manifestEntries>
</archive>
I do not know for what reason this code works in eclipse, but not in IntelliJ
This it correct.
<archive>
<manifestEntries>
<Dependencies>one.jar, two.rar, other.jar</Dependencies>
</manifestEntries>
</archive>
Manifest.mf worked!!!
I hope this helps.
There are several ways to generate executable jars. Using IntelliJ's GUI feature is one good way. Another way is to use Maven (or similarly in gradle, buildr, etc) which is build-server friendly:
It's more or less copy pasteable from the optaplanner examples maven build:
To have no problem like Manifest, you should have a directory named "META-INF" in "src" directory. So, create it and put a file named "MANIFEST.MF" in it with the following contents:
Manifest-Version: 1.0
Main-Class: <packageName>.Main
Not to forgot to replace the package's name containing Main class above!