我正在尝试为tornadofx项目构建一个jar文件,
当我在my.kt中运行主要功能时,它可以正常运行 (seri / src / main / kotlin / my.kt)
package com.serious
import tornadofx.*
import tornadofx.App
import tornadofx.launch
fun main() {
launch<MyApp>()
}
class MyApp : App(primaryView = ViewX::class)
//-------------------------
class ViewX : View("My View") {
override val root = vbox {
button("add an item") {
}
}
}
build.gradle文件
buildscript {
ext.kotlin_version = "1.2.60"
ext.tornadofx_version = "1.7.17"
ext.junit_version = "5.1.0"
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.junit.platform:junit-platform-gradle-plugin:1.1.0"
}
}
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.3.31'
id 'org.openjfx.javafxplugin' version '0.0.7'
}
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
testCompile group: 'junit', name: 'junit', version: '4.12'
compile 'no.tornado:tornadofx:1.7.18'
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
javafx {
version = "12.0.1"
modules = ['javafx.controls']
}
运行Windows 10,智能IDEA 2019.1.1 我在项目结构中创建了一个jar构件,并从构建菜单中创建了“构建构件”,它构建了一个jar文件,但未运行,并显示错误“错误:无法找到或加载主类com.serious.MyApp 造成原因:java.lang.NoClassDefFoundError:tornadofx / App “
答案 0 :(得分:0)
不确定这是否是最佳解决方案,但是您可以将shadow插件用于gradle。它允许轻松创建胖/超级JAR。您需要做的就是稍微修改build.gradle文件:
plugins {
id "application"
id "org.jetbrains.kotlin.jvm" version "1.3.11"
id "com.github.johnrengelman.shadow" version "4.0.2" // 5.0.0 for gradle 5.0+
}
mainClassName = "com.serious.MyKt"
repositories {
mavenLocal()
mavenCentral()
maven {
url "https://oss.sonatype.org/content/repositories/snapshots/"
}
}
ext {
tornadofx_version = "1.7.18"
junit_version = "5.4.0"
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib"
implementation "no.tornado:tornadofx:$tornadofx_version"
testImplementation "org.junit.jupiter:junit-jupiter:$junit_version"
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
test {
useJUnitPlatform()
}
然后运行名为“ shadowJar”的任务。胖子罐将放入/build/libs/
。