使用JavaFX和Maven将模块描述符添加到库 [英] Add module descriptor to library with JavaFX and maven

查看:87
本文介绍了使用JavaFX和Maven将模块描述符添加到库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在JavaFX的Maven项目中使用 Reflections ,我想使用jlink 捆绑一个最小的JRE.

I need to use Reflections in a maven project with JavaFX and I want to use jlink to bundle a minimal JRE.

问题是运行 mvn clean compile javafx:jlink 时出现以下错误:

The problem is that I get the following error when running mvn clean compile javafx:jlink:

[WARNING] Required filename-based automodules detected. Please don't publish this project to a public artifact repository!
Error: automatic module cannot be used with jlink: reflections from file:///C:/Users/Daniel/.m2/repository/org/reflections/reflections/0.9.12/reflections-0.9.12.jar
[ERROR] Command execution failed.
org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)
    at org.apache.commons.exec.DefaultExecutor.executeInternal (DefaultExecutor.java:404)
    at org.apache.commons.exec.DefaultExecutor.execute (DefaultExecutor.java:166)
    at org.openjfx.JavaFXBaseMojo.executeCommandLine (JavaFXBaseMojo.java:504)
    at org.openjfx.JavaFXBaseMojo.executeCommandLine (JavaFXBaseMojo.java:394)
    at org.openjfx.JavaFXJLinkMojo.execute (JavaFXJLinkMojo.java:187)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:564)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)
        at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:404)
        at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:166)
        at org.openjfx.JavaFXBaseMojo.executeCommandLine(JavaFXBaseMojo.java:504)
        at org.openjfx.JavaFXBaseMojo.executeCommandLine(JavaFXBaseMojo.java:394)
        at org.openjfx.JavaFXJLinkMojo.execute(JavaFXJLinkMojo.java:187)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:957)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:289)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:193)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:564)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)

问题在于反射不支持JPMS,而 jlink 仅需要显式模块.

The problem is that Reflections do not support JPMS and jlink requires explicit modules only.

我已经看到了此答案,它描述了如何将外部JAR转换为模块,但是我需要自动执行此操作在运行 jlink 之前,在我的Maven构建中.

I have seen this answer that describes how to convert an external JAR to a module but I need to do this automatically in my maven build before running jlink.

我还遇到了 moditect 完全可以做到这一点,但是由于我不知道如何告诉 javafx:jlink 使用经反射的库的转换后的JAR,我没有在我的项目中完成该工作

I also came across moditect that allows exactly this but I did not made that work in my project as I do not know how to tell javafx:jlink to use the converted JAR of the Reflections-library

我也可以想象使用 exec-maven-plugin 运行jlink命令,但我不知道如何告诉javafx-maven-plugin在不修改本地存储库的情况下采用该命令.

I could also imagine to use the exec-maven-plugin to run the jlink command but I do not know how to tell the javafx-maven-plugin to take that while not modifying the local repository.

在将自动模块(Reflections)作为依赖项时,如何使用 javafx-maven-plugin jlink 目标?

How can I use the jlink-goal of the javafx-maven-plugin while having an automated module (Reflections) as a dependency?

我的 module-info.java 看起来像这样(简化):

My module-info.java looks like this (simplified):

module my.project{
    exports my.project.toscan to reflections;
    exports my.project.ui to javafx.graphics;
    opens my.project.ui.controllers to javafx.fxml;
    requires javafx.controls;
    requires javafx.fxml;
    requires transitive javafx.graphics;
    requires javafx.base;
    requires reflections;
}

这是我的 pom.xml (也已简化):

and this is my pom.xml (also simplfied):

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>my</groupId>
    <artifactId>project</artifactId>
    <version>myversion</version>
    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>14</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>14</version>
        </dependency>
        <dependency>
            <groupId>org.reflections</groupId>
            <artifactId>reflections</artifactId>
            <version>0.9.12</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>14</release>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.4</version>
                <configuration>
                    <source>14</source>
                    <target>14</target>
                    <release>14</release>
                    <mainClass>my.project.MainClass</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>


这类似于此问题,稍后会问到.

推荐答案

您为什么坚持专门使用此工具链?您可以使用jlink创建JavaFX程序,而不必先对所有模块进行模块化.也许您可以按照我在Dirk中描述的路线进行操作: https://github.com/dlemmermann/JPackageScriptFX好处基本上是相同的,我看不到在整个应用程序中使用jlink会有任何其他好处.

Why do you insist on spcifically using this tool chain? You can make use of jlink to create a JavaFX program without having to modularize everything first. Perhaps you can follow the route I have described with Dirk here: https://github.com/dlemmermann/JPackageScriptFX The benefits are basically the same and I don't see any additional benefit of using jlink for the whole application.

这篇关于使用JavaFX和Maven将模块描述符添加到库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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