因为我正在尝试运行Springboot应用程序,所以诀窍是不要像通常那样尝试启动主类,而是使用
org.springframework.boot.loader.JarLauncher
这在一篇文章中得到了更恰当的解释
blog post
春天队
因此,Springboot的完整工作示例如下所示:
plugins {
id 'org.springframework.boot' version '2.6.0-SNAPSHOT'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'org.panteleyev.jpackageplugin' version '1.3.1'
id 'application'
}
group = 'space.forloop'
version = '1.0.6'
compileJava.options.encoding = 'UTF-8'
compileTestJava.options.encoding = 'UTF-8'
javadoc.options.encoding = 'UTF-8'
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
application {
mainClass = 'com.example.Application'
applicationDefaultJvmArgs = ["-Dfile.encoding=UTF-8"]
}
bootJar {
manifest {
attributes 'Implementation-Version': "${project.version}"
attributes 'Implementation-Title': "${project.name}"
}
}
// Not required but useful if you want to configure a little more.
def os = org.gradle.internal.os.OperatingSystem.current()
def pkgType = os.windows ? 'msi' : os.linux ? 'deb' : 'pkg'
jpackage {
dependsOn "bootJar"
type = pkgType
input = "${buildDir}/libs"
destination = "${buildDir}/dist"
appName = 'Example'
vendor = 'com.example'
mainJar = bootJar.archiveFileName.get()
mainClass = "org.springframework.boot.loader.JarLauncher"
javaOptions = ['-Dfile.encoding=UTF-8']
macPackageName = bootJar.archiveBaseName.get()
}