问题
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.
回答1:
I had the same problem.
Make sure your MANIFEST.MF is in:
src/main/resources/META_INF/
NOT
src/main/java/META_INF/
回答2:
To fix:
- File > Project Structure
- Under Project Settings on the left, select "Artifacts"
- Find the JAR definition In the middle pane and select it
- In the left pane of the "Output Layout" tab find the jar file in the list and select it
- At the bottom, click the "Use Existing Manifest" button and select the manifest file that is in your project source.
- Click OK and run the build
回答3:
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:
- Project Structure -> Artifacts -> + Jar -> Empty
- Centre pane now has Create Manifest and Use Existing Manifest buttons. Use one of these.
- I had difficulty if I extracted dependent libraries with their own manifests into the output root, they seemed to intermittently overwrite the new manually created manifest. Messing around with order of operations seemed to make it work.
UPDATE:
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>
回答4:
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>
回答5:
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.
回答6:
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:
- The end-user jar (optaplanner-examples-*.jar) must include the classpath of its dependencies in its manifest.
- The sh and bat script must then run that jar with accordingly.
回答7:
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!
来源:https://stackoverflow.com/questions/32037586/java-manifest-file-invalid-after-exporting-project