【发布时间】:2019-12-04 14:04:32
【问题描述】:
我有一个用于 HelloWorld 的 Intellij Gradle 项目。该程序在 IDE 中运行,但运行 jar 文件时出现无效或损坏的 jar 错误。我对 build.gradle 和 Manifest 进行了一些更改,但仍然无法运行。我使用的是 Ubuntu 16.04。
我认为问题与清单有关。
IDE -
Intellij - 2019.2 Gradle 项目
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'
}
类-
public class Hello {
public static void main(String[] args) {
// Prints "Hello, World" to the terminal window.
System.out.println("Hello, World");
}
}
错误:无效或损坏的 jarfile HelloWorldArt.main.jar
树 -
. ├── 建造 │ ├── 类 │ │ └── java │ │ └── 主要 │ │ └── Hello.class │ └── tmp │ └── compileJava ├── build.gradle ├── 毕业 │ └── 包装 │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── 毕业 ├── gradlew.bat ├── META-INF │ └── MANIFEST.MF ├──出 │ └── 文物 │ ├── HelloWorldArt_jar │ │ └── HelloWorldArt.jar │ └── HelloWorldArt_main_jar │ └── HelloWorldArt.main.jar ├── settings.gradle ├── 源 │ ├── 主要 │ │ ├── java │ │ │ ├── Hello.java │ │ │ └── META-INF │ │ │ └── MANIFEST.MF │ │ └── 资源 │ └── 测试 │ ├── java │ └── 资源【问题讨论】:
-
你可以尝试从 gradle 的 jar 部分中的 {configurations.runtimeClasspath.collect...} 中删除吗?
-
@Sambit - 更改后出现同样的错误。
-
重新创建 JAR 文件。
-
@user207421 现在可以工作了,问题是两个清单文件。
标签: java gradle intellij-idea intellij-13