'IntelliJ no Main Manifest Attribute after creating jar artifact

I am trying to build an jar artefact from this repository. I imported apache commons io and org.json as libraries. When extracting the artifact I find a Manifest file which only contains the information of org.json. You can find the jar here. The manifest file in my Project is not reflected at all. Any help is appreciated. When I run the jar in console with java -jar I get the

Error: No Main Manifest Attribute in XXX.jar.



Solution 1:[1]

From the project you provided on github i made the following changes to make it run with java -jar. But first and foremost the project you linked on github does not build with gradle build on a fresh pull.

to make this run you need to add commons io and org.json to you build.gradle file. this makes the build.gradle file look like:

plugins {
    id 'java'
}

version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    compile group: 'commons-io', name: 'commons-io', version: '2.6'
    compile group: 'org.json', name: 'json', version: '20190722'
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

jar {
    manifest {
        attributes(
                'Main-Class': 'de.bergwacht.esslingen.Main'
        )
    }
}

your project also has alot of unused dependencies that should be removed that were creating gradle warnings.

in AnweseneheitsTableModel remove the imports:

import com.sun.org.apache.xpath.internal.operations.Bool;

in DienstprotokollInvalidArgumentException remove the imports:

import com.sun.javaws.exceptions.InvalidArgumentException;

in MainForm remove the imports:

import com.sun.org.apache.xpath.internal.operations.Bool;
import com.sun.xml.internal.fastinfoset.algorithm.BooleanEncodingAlgorithm;

at this point you can run ./gradlew jar and this will create a jar for you under build/libs

you can run that jar with java -jar build/libs/BWOrgaTool-1.0-SNAPSHOT.jar

that command will run it, it will encounter a NPE:

Exception in thread "main" java.lang.NullPointerException
    at de.bergwacht.esslingen.forms.MainForm.<init>(MainForm.java:138)
    at de.bergwacht.esslingen.Main.main(Main.java:42)

but thats another problem all together, you can start debugging your program at that point.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 scigs