I have a Intellij Gradle project for HelloWorld. The program runs in the IDE but running the jar files with an invalid or corrupt jar error. I made several changes to the build.gradle and Manifest and still this does not run. I am using Ubuntu 16.04.
I think the issue is related to the manifest.
IDE -
Intellij - 2019.2 Gradle Project
Java - java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)
build.gradle -
plugins {
id 'java'
}
group 'com.HelloWorldTesting'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
jar {
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
manifest {
attributes(
'Implementation-Title': 'Hello World',
"Main-Class": "com.HelloWorldTesting.Hello"
)
}
archivesBaseName = 'app'
}
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
}
Class -
public class Hello {
public static void main(String[] args) {
// Prints "Hello, World" to the terminal window.
System.out.println("Hello, World");
}
}
Error: Invalid or corrupt jarfile HelloWorldArt.main.jar
tree -
. ├── build │ ├── classes │ │ └── java │ │ └── main │ │ └── Hello.class │ └── tmp │ └── compileJava ├── build.gradle ├── gradle │ └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── META-INF │ └── MANIFEST.MF ├── out │ └── artifacts │ ├── HelloWorldArt_jar │ │ └── HelloWorldArt.jar │ └── HelloWorldArt_main_jar │ └── HelloWorldArt.main.jar ├── settings.gradle ├── src │ ├── main │ │ ├── java │ │ │ ├── Hello.java │ │ │ └── META-INF │ │ │ └── MANIFEST.MF │ │ └── resources │ └── test │ ├── java │ └── resources