Javafx 10或更低版本,可下载以创建可运行的jar文件 [英] Javafx 10 or older for download to create a runnable jar file

查看:345
本文介绍了Javafx 10或更低版本,可下载以创建可运行的jar文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找javafx 10或更高版本.我目前有javafx-sdk-11,并试图使我的程序成为一个可运行的jar文件,但显然自javafx 11起,该选项不再可用.

I am looking for javafx 10 or newer. I currently have javafx-sdk-11 and trying to make my programme a single runnable jar file, but apparently since javafx 11, that option isn't available anymore.

所以我必须去终端并输入以下行来运行它:

So I have to go to the terminal and type the following line to run it :

java --module-path /path/to/javafx/javafx-sdk-11.0.2 or another/lib --add-modules javafx.controls,javafx.fxml,javafx.graphics,javafx.web -jar /path/to/GUI_Music_Gen.jar

由于找不到可下载的旧版本Javafx,请寻求您的帮助.如果有人可以帮助我,请告诉我.提前致谢. 顺便说一句,我不知道这是否会成为兼容性问题,但我运行的是macOS X.

Since I can't find older versions of javafx available for download, I ask for your help. If anybody can help me, let me know. Thanks in advance. Btw, I don't know if this will be an issue for compatibility, but I run macOS X.

推荐答案

我建议使用诸如grade或maven之类的依赖项管理来运行JavaFX并构建可用的Jar.

I would recommend using dependency management like grade or maven to run JavaFX and Build a working Jar.

我可以为您运行的JavaFX项目提供此build.gradle:

I can offer you this build.gradle for a working JavaFX project:


buildscript {
    dependencies {
        classpath group: 'de.dynamicfiles.projects.gradle.plugins', name: 'javafx-gradle-plugin', version: '8.7.0'
        classpath 'org.openjfx:javafx:11'

    }
    repositories {
        mavenLocal()
        mavenCentral()
        maven {
            url "https://plugins.gradle.org/m2/"
        }

    }
}

plugins {
    id 'java'
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.8'
}

sourceCompatibility = 11
targetCompatibility = 11
repositories {
    jcenter()
    mavenCentral()
}

// configure here

mainClassName = "your.app.main"

publishing {
    publications {
        mavenAar(MavenPublication) {
            from components.java
            afterEvaluate {
                artifact javadocJar
                artifact sourcesJar
            }
        }
    }
}

javafx {
    version = "11"
    modules = ['javafx.controls', 'javafx.fxml', 'javafx.graphics']
}


sourceSets {
    main.java.srcDir "src/main/java"
    main.resources.srcDir "src/main/resources"
}


dependencies {
    api 'org.apache.commons:commons-math3:3.6.1'
    implementation 'com.google.guava:guava:27.0.1-jre'
    testImplementation 'junit:junit:4.12'
    // use java fx just like a regular dependency :) 
    implementation 'org.openjfx:javafx:11'
    compile group: 'org.openjfx', name: 'javafx', version: '11.0.2'
}

// important Configure your project 
jar {
    manifest {
        attributes(
                'Main-Class': 'your.app.main'
        )

    }
    from {
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
}

compileJava {
    doFirst {
        options.compilerArgs = [
                '--module-path', classpath.asPath,
                '--add-modules', 'javafx.controls,javafx.fxml,javafx.graphics'
        ]
        println options.compilerArgs
    }
}

只需将"your.project.main"替换为实际的主类,一切就可以正常运行.

Just replace "your.project.main" with your actual main class and everything should run fine.

同样重要的是,主类不要从Application扩展. 它应该只启动应用程序.

Also it is really important that your Main class does not extend from Application. It should only Launch the Application.

这篇关于Javafx 10或更低版本,可下载以创建可运行的jar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆