相关疑难解决方法(0)

JavaFX 11:使用Gradle创建一个jar文件

我正在尝试将JavaFX项目从8 Java版升级到11版.当我使用"运行"Gradle任务(我遵循Openjfx教程)时,它工作,但是当我构建(使用"jar"Gradle任务)并执行(使用"java -jar")jar文件时,消息"Error :缺少JavaFX运行时组件,并且"运行此应用程序需要".

这是我的build.gradle文件:

group 'Project'
version '1.0'
apply plugin: 'java'
sourceCompatibility = 1.11

repositories {
    mavenCentral()
}

def currentOS = org.gradle.internal.os.OperatingSystem.current()
def platform
if (currentOS.isWindows()) {
    platform = 'win'
} else if (currentOS.isLinux()) {
    platform = 'linux'
} else if (currentOS.isMacOsX()) {
    platform = 'mac'
}
dependencies {
    compile "org.openjfx:javafx-base:11:${platform}"
    compile "org.openjfx:javafx-graphics:11:${platform}"
    compile "org.openjfx:javafx-controls:11:${platform}"
    compile "org.openjfx:javafx-fxml:11:${platform}"
}

task run(type: JavaExec) {
    classpath sourceSets.main.runtimeClasspath
    main = "project.Main"
}

jar {
    manifest {
        attributes 'Main-Class': 'project.Main'
    }
    from …
Run Code Online (Sandbox Code Playgroud)

jar gradle java-11 javafx-11

27
推荐指数
3
解决办法
1万
查看次数

缺少Maven Shade JavaFX运行时组件

我正在尝试使用maven依赖项创建一个JFX11自包含jar.从我所做的研究来看,似乎最好的方法是通过maven shade插件.但是,当我运行它时,我收到此错误:

错误:缺少JavaFX运行时组件,并且需要运行此应用程序

我不明白为什么会这样.我搞砸了什么?有一个更好的方法吗?我也用同样的消息尝试了maven程序集插件.

pom文件供参考

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>Application</groupId>
    <artifactId>Main</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>SpaceRunner</name>
    <url>http://maven.apache.org</url>
    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>11</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>10</release>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.6.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>java</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <mainClass>Application.Main</mainClass>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>
                                Application.Main
                            </mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.0</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>Application.Main</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution> …
Run Code Online (Sandbox Code Playgroud)

java javafx maven javafx-11

22
推荐指数
1
解决办法
7407
查看次数

Gradle badass-runtime-plugin和ProGuard Gradle插件

jPackage之前如何运行proguard?

介绍

我使用gradle插件在JavaFx中开发了一个应用程序,并使用gradle插件将其与jPackager打包在一起。

我使用的主要插件是:

id 'org.openjfx.javafxplugin' version '0.0.8'
id 'org.beryx.runtime' version '1.7.0'
id "com.github.johnrengelman.shadow" version "5.1.0"
Run Code Online (Sandbox Code Playgroud)

我当前的gradle版本是:gradle-5.6.2-all

问题描述

我如何使用proguard,以便在jPackage执行工作之前对代码进行混淆和优化?

我可以运行proguard任务,但是当我运行jPackage时,代码不会混淆!

Ive找到了较早的gradle版本的教程(Tutorial),但是我不确定如何将其与当前插件混合使用。我已经尝试了一些代码片段,但是它们都无法构建,并且我不想用一堆无法正常工作的代码来使这个话题变得混乱。

我当前的工作build.gradle

// 1. Include proguard dependency
buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'net.sf.proguard:proguard-gradle:6.2.0'
    }
}

plugins {
    id 'java'
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.8'
    id 'org.beryx.runtime' version '1.7.0'
    id "com.github.johnrengelman.shadow" version "5.1.0"

}


dependencies {
    compile "org.controlsfx:controlsfx:11.0.0"
    compile "eu.hansolo:tilesfx:11.13"
    compile "com.jfoenix:jfoenix:9.0.9"
    compile "org.apache.httpcomponents:httpclient:4.5.9"
    compile "org.json:json:20180813"
    compile "mysql:mysql-connector-java:8.0.17"
    compile "org.jasypt:jasypt:1.9.3"
    compile "com.mchange:c3p0:0.9.5.4" …
Run Code Online (Sandbox Code Playgroud)

java upgrade proguard gradle build.gradle

8
推荐指数
1
解决办法
210
查看次数

使用Gradle向运行时映像添加依赖项

我不知道如何添加依赖项。我的模块需要Log4j。我在模块信息中添加了要求。我还添加了gradle依赖项。我可以运行项目,但不能创建自定义运行时映像。

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

group 'eu.sample'
version '2.0'


repositories {
    mavenCentral()
}

javafx {
    modules = [ 'javafx.controls', 'javafx.fxml' ]
}

mainClassName = "$moduleName/eu.sample.app.Main"

def lin_java_home = hasProperty('org.gradle.java.home') ? getProperty('org.gradle.java.home') : System.getenv('JAVA_HOME')
def lin_fx_jmods = hasProperty('linux.fx.mods') ? getProperty('linux.fx.mods') : System.getenv('PATH_TO_FX_MODS_LIN')

def win_java_home = hasProperty('windows.java.home') ? getProperty('windows.java.home') : System.getenv('JAVA_HOME_WIN')
def win_fx_jmods = hasProperty('windows.fx.mods') ? getProperty('windows.fx.mods') : System.getenv('PATH_TO_FX_MODS_WIN')

dependencies {
    compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.11.1'
}

task jlink(type: Exec) {
    dependsOn 'clean' …
Run Code Online (Sandbox Code Playgroud)

java log4j javafx gradle

5
推荐指数
1
解决办法
868
查看次数

JavaFX Proguard混淆

我正在努力处理JavaFX应用程序的混淆问题。以该项目为基础:

https://github.com/openjfx/samples/tree/master/IDE/IntelliJ/Non-Modular/Gradle

Proguard抛出此错误:

java.io.IOException: Can't write [Path\infile.jar] (Can't read [Path\outfile.jar] (Duplicate jar entry [a.class]))
Run Code Online (Sandbox Code Playgroud)

Proguard配置文件:-dontoptimize -dontshrink

-libraryjars 'E:\Prog\jdk-11.0.2\jmods'
-libraryjars 'E:\Prog\javafx-sdk\lib'

# Save meta-data for stack traces
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable

# Rename FXML files together with related views
-adaptresourcefilenames **.fxml,**.png,**.css
-adaptresourcefilecontents **.fxml
-adaptclassstrings

# Keep all annotations and meta-data
-keepattributes *Annotation*,Signature,EnclosingMethod

# Keep entry-point class
-keep classpackage.App {
    public static void main(java.lang.String[]);
}

# Keep all classes inside application
-keep,allowobfuscation class package.** {
}

# Keep names of fields marked …
Run Code Online (Sandbox Code Playgroud)

obfuscation javafx proguard java-11 javafx-11

5
推荐指数
1
解决办法
875
查看次数

如何从javaFX应用程序创建jar文件,并从命令行获取所有模块依赖项?

我有一个Javafx应用程序,我想通过Windows命令提示符将其及其模块依赖项(javaFX)压缩到一个jar文件中,以便您可以在任何地方双击运行它而无需javafx sdk。

我正在使用的javaFX模块是控件和Web。

我已广泛搜索有关如何执行此操作的信息。但是,我所发现的只是与javaFX模块一起运行jar的东西。但是,这不符合单个jar文件的要求,因为您需要单独下载javaFX sdk。

java javafx jar

5
推荐指数
0
解决办法
76
查看次数