Create an excutable jar in IntelliJ IDEA

前提是你 提交于 2019-11-27 18:51:55
Dan

I have experienced the same issue and found a fix and/or bug in how Intellij auto populates the path for the manifest.

INTELLIJ UI

When creating an artifact to create jar files, IntelliJ auto populates the the path where the current manifest is located.

i.e. After choosing Main-Class in the artifact creation page, Intellij will add automatically the following path \src\java\META-INF\MANIFEST.MF. For some reason, the build command never takes the mentioned MANIFEST.MF File. It creates one from scratch without the Main-Class definition which results on the "Failed to load Main-Class"

If using the IntelliJ UI to create jar artifacts; removed the auto populate path by changing it to /$PROJECT_DIR/src/ and click OK.

Example of what it looks like by default:

Now this is what it should look like after the change:

MANUAL FIX TO ENTER CORRECT MANIFEST.MF FILE

On the IntelliJ project , open .idea\artifacts\_jar.xml

Make sure it contains

  <element id="directory" name="META-INF">
    <element id="file-copy" path="$PROJECT_DIR$/src/META-INF/MANIFEST.MF" />
  </element>

You might need to reload intelliJ once you do this so it picks up on the changes to the .xml file

For me it happened on maven projects where a different structure exists (i.e. src/main/java/..).

I am using OSX 10.9.2 with IntelliJ version 12.1.6

Hope that helps.

One of the important rule is that Manifest file must end with new line or carriage return character. If it is not there then add now.

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