Wrong Manifest.mf in IntelliJ IDEA created .jar

拟墨画扇 提交于 2019-11-26 23:29:39

I had the same problem.

Make sure your MANIFEST.MF is in:

src/main/resources/META_INF/

NOT

src/main/java/META_INF/

To fix:

  1. File > Project Structure
  2. Under Project Settings on the left, select "Artifacts"
  3. Find the JAR definition In the middle pane and select it
  4. In the left pane of the "Output Layout" tab find the jar file in the list and select it
  5. At the bottom, click the "Use Existing Manifest" button and select the manifest file that is in your project source.
  6. Click OK and run the build
DS Justice

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>

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:

  1. The end-user jar (optaplanner-examples-*.jar) must include the classpath of its dependencies in its manifest.
  2. The sh and bat script must then run that jar with accordingly.
Mohsen Abasi

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!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!