[英]trying to create a jar executable in IntelliJ IDEA
I'm trying to build a jar file for a tornadofx project,我正在尝试为 tornadofx 项目构建一个 jar 文件,
it runs normally when i run the main function in my.kt (seri/src/main/kotlin/my.kt)当我在 my.kt (seri/src/main/kotlin/my.kt) 中运行 main 函数时,它运行正常
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") {
}
}
}
the build.gradle file 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']
}
running windows 10, intelli IDEA 2019.1.1 i made a jar artifact in the project structure,and 'build artifacts' from build menu,, it built a jar file but it's not running, shows error " Error: Could not find or load main class com.serious.MyApp Caused by: java.lang.NoClassDefFoundError: tornadofx/App "运行 Windows 10,intelli IDEA 2019.1.1 我在项目结构中制作了一个 jar 工件,并从构建菜单中“构建工件”,它构建了一个 jar 文件但它没有运行,显示错误“错误:无法找到或加载 main com.serious.MyApp 类引起:java.lang.NoClassDefFoundError:tornadofx/App“
Not sure if it's the optimal solution, but you can use shadow plugin for gradle.不确定这是否是最佳解决方案,但您可以使用 shadow plugin for gradle。 It allows to create fat\/uber JARs easily.它允许轻松创建胖\/超级 JAR。 All you need to do is to slightly modify your build.gradle file:您需要做的就是稍微修改您的 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()
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.