[英]Create executable JAR in Cucumber/Java project in Intellij/idea
[英]trying to create a jar executable in IntelliJ IDEA
我正在嘗試為 tornadofx 項目構建一個 jar 文件,
當我在 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") {
}
}
}
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,intelli IDEA 2019.1.1 我在項目結構中制作了一個 jar 工件,並從構建菜單中“構建工件”,它構建了一個 jar 文件但它沒有運行,顯示錯誤“錯誤:無法找到或加載 main com.serious.MyApp 類引起:java.lang.NoClassDefFoundError:tornadofx/App“
不確定這是否是最佳解決方案,但您可以使用 shadow plugin for 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()
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.