【发布时间】:2020-03-25 23:00:38
【问题描述】:
我正在尝试使用 gradle 同时运行一个主类和另一个 java 类(服务器),但由于某种原因,当我尝试运行服务器任务时,我不断收到此错误。
Error: Could not find or load main class task ':Server'
Caused by: java.lang.ClassNotFoundException: task ':Server'
这是我的 gradle.build
plugins {
id 'application'
id 'java'
id 'org.openjfx.javafxplugin' version '0.0.8'
}
javafx {
version = "11.0.2"
modules = [ 'javafx.controls', 'javafx.fxml' ]
}
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
sourceSets.main.java.srcDirs = ['src']
sourceSets {
main {
resources {
srcDirs = ["src"]
includes = ["**/*.css", "images/*png", "files/*.csv", "**/*.csv"]
}
}
}
dependencies {
compile group: 'commons-validator', name: 'commons-validator', version: '1.6'
compile group: 'com.google.code.gson', name: 'gson', version: '2.7'
}
apply plugin: 'java'
apply plugin: 'application'
applicationDefaultJvmArgs = ["-Djavafx.embed.singleThread=true"]
task(Server, dependsOn: 'classes', type: JavaExec) {
description = "Run the Server class"
classpath = sourceSets.main.runtimeClasspath
main = Server
}
defaultTasks 'Server'
mainClassName = 'Main'
【问题讨论】: