make - no main manifest attribute intellij gradle
Create an excutable jar in IntelliJ IDEA (5)
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.
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>
I am using IntelliJ IDEA 12.1.3. I have one module and I am trying to convert it into a jar as per the steps given here. I built the jar file and I moved the jar file to D:/. If I try to run this jar I get the following message:
Failed to load Main-Class manifest attribute from jar
If I run it using
java -classpath jar com.code.TestCase it works perfectly.
Why does this happen? I created the jar using IntelliJ IDEA. In that jar it has all the code for all external libraries which I added.
In the src manifest file:
Manifest-Version: 1.0 Main-Class: com.code.TestCase
but the jar's manifest file content is:
Manifest-Version: 1.0 Build-Jdk: 1.6.0 Built-By: ubuntu Created-By: Apache Maven Archiver-Version: Plexus Archiver Name: org.apache.log4j Implementation-Vendor: "Apache Software Foundation" Implementation-Title: log4j Implementation-Version: 1.2.15
Main-Class not added in the jar file MANIFEST.MF, but it has
Main-Class in src?
I have experienced the same issue and found a fix and/or bug in how Intellij auto populates the path for the manifest.
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.
- 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
“No auto configuration classes found in META-INF/spring.factories”
I solved it by deleting and then recreating the maven repository folder (inside the .m2 folder) .
Then I ran
and got a build success !