【发布时间】:2020-11-07 00:30:56
【问题描述】:
我用 gradle 生成一个 jar 文件来测试我的程序,但是当我运行命令时:
Java -jar file_name .jar
我总是遇到同样的错误:
Error: Could not find or load main class home.Main
Caused by: java.lang.ClassNotFoundException: home.Main
build.gradle:
plugins {
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.8'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile 'com.jfoenix:jfoenix:9.0.8'
}
javafx {
version = "14"
modules = [ 'javafx.controls', 'javafx.fxml']
}
jar {
manifest {
attributes(
'Class-Path': configurations.compile.files.collect {"$it.name"}.join(' '),
'Main-Class': 'home.Main')}
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}
【问题讨论】: