I\'m kind of going crazy with this error I get when running a JAR file built off Gradle. The error reads \"no main manifest attribute, in RxJavaDemo.jar\" I tried manipulat
To make the jar file executable (so that the java -jar command works), specify the Main-Class attribute in MANIFEST.MF.
In Gradle, you can do it by configuring the jar task.
tasks.withType {
manifest {
attributes["Main-Class"] = "com.caco3.Main"
}
}
mainClassName does not work as expected?Or why mainClassName does not specify the attribute in the manifest?
The mainClassName property comes from the application plugin. The plugin:
makes it easy to start the application locally during development, and to package the application as a TAR and/or ZIP including operating system specific start scripts.
So the application plugin does not aim at producing executable jars
When a mainClassName property set, then:
$ ./gradlew run will launch the main method in the class specified in the attributezip/tar archive built using distZip/distTar tasks will contain a script, which will launch the main method of the specified previously class.Here is the line of shell script setting the main class:
$ grep Main2 gradletest
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLETEST_OPTS -classpath "\"$CLASSPATH\"" com.caco3.gradletest.Main2 "$APP_ARGS"