Gradle - 没有主要清单属性 [英] Gradle - no main manifest attribute
问题描述
我正在用 Gradle 构建一个 JAR 文件.当我尝试运行它时出现错误
I'm building a JAR file with Gradle. When I try to run it I get the error
没有主要清单属性,在 RxJavaDemo.jar 中
no main manifest attribute, in RxJavaDemo.jar
我尝试操作 Manifest 属性,但我想我忘记添加依赖项或其他内容.我到底做错了什么?
I tried manipulating the Manifest property but I think I'm forgetting to add the dependencies or something to it. What exactly am I doing wrong?
apply plugin: 'java'
apply plugin: 'application'
mainClassName = 'demo.MainDashboard'
dependencies {
compile files ("H:/Processes/Development/libraries/hikari-cp/HikariCP-2.4.1.jar")
compile files ("H:/Processes/Development/libraries/controls-fx/controlsfx.jar")
compile files ("H:/Processes/Development/libraries/database_connections/sqlite-jdbc-3.8.6.jar")
compile files ("H:/Processes/Development/libraries/guava/guava-18.0.jar")
compile files ("H:/Processes/Development/libraries/rxjava/rxjava-1.0.12.jar")
compile files ("H:/Processes/Development/libraries/rxjava-extras/rxjava-extras-0.5.15.jar")
compile files ("H:/Processes/Development/libraries/rxjavafx/RxJavaFX-1.0.0-RC1-SNAPSHOT.jar")
compile files ("H:/Processes/Development/libraries/rxjavaguava/rxjava-guava-1.0.3.jar")
compile files ("H:/Processes/Development/libraries/rxjava-jdbc/rxjava-jdbc-0.6.3.jar")
compile files ("H:/Processes/Development/libraries/slf4j/slf4j-api-1.7.12.jar")
compile files ("H:/Processes/Development/libraries/tom-commons/tom-commons.jar")
}
sourceSets {
main.java.srcDir "src/main/java"
main.resources.srcDir "src/main/resources"
}
jar {
manifest {
attributes(
"Class-Path": configurations.compile.collect { it.getName() }.join(' '))
}
from configurations.compile.collect { entry -> zipTree(entry) }
}
推荐答案
尝试更改您的清单属性,例如:
Try to change your manifest attributes like:
jar {
manifest {
attributes(
'Class-Path': configurations.compile.collect { it.getName() }.join(' '),
'Main-Class': 'hello.HelloWorld'
)
}
}
然后只需将 'hello.helloWorld'
更改为 '
(其中 Main 类具有主要方法).在这种情况下,您在清单中创建一个指向此类的属性,然后运行一个 jar.
And then just change 'hello.helloWorld'
to '<your packagename>.<the name of your Main class>'
(where your Main class has a main method). In this case, you make in your manifest an attribute, which point to this class, then a jar is running.
这篇关于Gradle - 没有主要清单属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!