【问题标题】:JavaFx : create jar under linux and run it under windows 10JavaFx:在linux下创建jar并在windows 10下运行
【发布时间】:2020-06-10 12:19:10
【问题描述】:

我有一个在 Linux 下开发的简单 Java FX(11.x LTS) 应用程序。我想创建一个 jar 文件在 win 10 下执行。为此我有以下 pom.xml :

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>groupId</groupId>
    <artifactId>udp_dumper</artifactId>
    <version>1.0-SNAPSHOT</version>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.3</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>Launcher</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <release>11</release>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.4</version>
                <configuration>
                    <mainClass>Launcher</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>11.0.2</version>
            <classifier>linux</classifier>
        </dependency>

        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>11.0.2</version>
            <classifier>win</classifier>
        </dependency>

        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>11.0.2</version>
            <classifier>linux</classifier>
        </dependency>

        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>11.0.2</version>
            <classifier>win</classifier>
        </dependency>

    </dependencies>
</project>

在 Windows 上,我下载了 JavaFX SDk 并将其路径放入 PATH 变量(bin 和 lib 文件夹)。我正在尝试通过java -jar *.jar 执行它 但我收到以下错误:

java.lang.ClassNotFoundException: com.sun.glass.ui.win.WinPlatformFactory

失败的原因是什么? 我是否使用有效的方法来部署 JavaFX 应用程序?

【问题讨论】:

  • 查看this answer;它显示了使用 Maven 创建一个胖罐子。我相信具有平台特定代码的模块是javafx.graphicsjavafx.mediajavafx.web。在您使用的那些中,您必须为要支持的每个平台手动声明一个依赖项。因此,在您的情况下,我认为您需要为 javafx.graphics 添加 linuxwin 依赖项。
  • YEEEES,它有效!!!!你是摇滚明星!!!!非常感谢您的帮助

标签: java maven javafx


【解决方案1】:

正如@JoséPereda 的this answer 所解释的,您必须为某些JavaFX 模块(更具体地说,包含特定平台代码的模块)包含每个特定于平台的依赖项,以便创建一个跨平台的胖jar。我相信这些模块是javafx.graphicsjavafx.mediajavafx.web。在您使用的那些中,您必须为要支持的每个平台手动声明一个依赖项。在您的情况下,我相信以下内容就足够了:

<dependencies>
  <dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-graphics</artifactId>
    <version>${javafx.version}</version>
    <classifier>win</classifier>
  </dependency>

  <dependency>
    <groupId>org.openjfx</groupId>
    <artifactId></artifactId>
    <version>${javafx.version}</version>
    <classifier>linux</classifier>
  </dependency>

  <dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-controls</artifactId>
    <version>${javafx.version}</version>
  </dependency>

  <dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-fxml</artifactId>
    <version>${javafx.version}</version>
  </dependency>
</dependencies>

【讨论】:

    猜你喜欢
    • 2012-02-05
    • 2020-07-08
    • 1970-01-01
    • 2020-04-02
    • 1970-01-01
    • 2014-04-01
    • 2013-03-25
    • 2014-04-11
    • 2012-12-28
    相关资源
    最近更新 更多