繁体   English   中英

试图在 IntelliJ IDEA 中创建 jar 可执行文件

[英]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()
}

Intellij Gradle<\/a>

最简单的方法是点击 Gradle -> build -> bootJar

Fat jar 将在 build\/libs 文件夹中创建

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM