JavaFX Maven с moditect и Java 11

Согласно Есть ли способ добавить зависимости maven при использовании maven-jlink-plugin? Кто-нибудь использовал подключаемый модуль ModiTect Maven с JavaFX в Java 11. Я пробовал использовать maven-jlink-plugin с:

 <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jlink-plugin</artifactId>
    <version>3.0.0-alpha-1</version>
    <extensions>true</extensions>
    <dependencies>
        <dependency>
            <groupId>org.ow2.asm</groupId>
            <artifactId>asm</artifactId>
            <version>6.2</version> <!-- Use newer version of ASM -->
        </dependency>
    </dependencies>
</plugin>            

Но получил:

--- maven-jlink-plugin:3.0.0-alpha-1:jlink (default-jlink) @ test33 ---
Toolchain in maven-jlink-plugin: jlink [ C:\Program Files\Java\jdk-11\bin\jlink.exe ]
The following dependencies will be linked into the runtime image:
 -> module: javafx.controlsEmpty ( C:\Users\md\.m2\repository\org\openjfx\javafx-controls\11-ea+25\javafx-controls-11-ea+25.jar )
 -> module: javafx.controls ( C:\Users\md\.m2\repository\org\openjfx\javafx-controls\11-ea+25\javafx-controls-11-ea+25-win.jar )
 -> module: javafx.graphicsEmpty ( C:\Users\md\.m2\repository\org\openjfx\javafx-graphics\11-ea+25\javafx-graphics-11-ea+25.jar )
 -> module: javafx.graphics ( C:\Users\md\.m2\repository\org\openjfx\javafx-graphics\11-ea+25\javafx-graphics-11-ea+25-win.jar )
 -> module: javafx.baseEmpty ( C:\Users\md\.m2\repository\org\openjfx\javafx-base\11-ea+25\javafx-base-11-ea+25.jar )
 -> module: javafx.base ( C:\Users\md\.m2\repository\org\openjfx\javafx-base\11-ea+25\javafx-base-11-ea+25-win.jar )
 -> module: javafx.fxmlEmpty ( C:\Users\md\.m2\repository\org\openjfx\javafx-fxml\11-ea+25\javafx-fxml-11-ea+25.jar )
 -> module: javafx.fxml ( C:\Users\md\.m2\repository\org\openjfx\javafx-fxml\11-ea+25\javafx-fxml-11-ea+25-win.jar )
 -> module: javafx.mediaEmpty ( C:\Users\md\.m2\repository\org\openjfx\javafx-media\11-ea+25\javafx-media-11-ea+25.jar )
 -> module: javafx.media ( C:\Users\md\.m2\repository\org\openjfx\javafx-media\11-ea+25\javafx-media-11-ea+25-win.jar )

Error: automatic module cannot be used with jlink: javafx.mediaEmpty from file:///C:/Users/mduso/.m2/repository/org/openjfx/javafx-media/11-ea+25/javafx-media-11-ea+25.jar

Из прочтения другого поста я знаю, что мне нужно сгенерировать информацию о модуле, но надеялся, что кто-то уже использовал плагин ModiTect Maven в своем pom, чтобы делать это автоматически для них каждый раз.

Я собираюсь использовать JavaFX со своими учениками во всех их программах и не хочу, чтобы все они делали это каждый раз вручную для всех модулей JavaFX.
ИЗМЕНИТЬ
Я попытался сделать это с помощью следующей пометки.

<?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>md</groupId>
    <artifactId>test33</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>test33</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <mainClass>md.test33.MainApp</mainClass>
    </properties>

    <organization>
        <!-- Used as the 'Vendor' for JNLP generation -->
        <name>Your Organisation</name>
    </organization>

    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>11-ea+25</version>

        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>11-ea+25</version>

        </dependency>

    </dependencies>

    <build>
        <plugins>
            <!-- sets up the version of Java you are running and complines the Code -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>11</release>  <!-- or <release>10</release>-->
                </configuration>

            </plugin>
            <!-- used to make the program run -->            
            <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>${mainClass}</mainClass>
                </configuration>
            </plugin>     




            <plugin>
                <groupId>org.moditect</groupId>
                <artifactId>moditect-maven-plugin</artifactId>
                <version>1.0.0.Beta1</version>
                <executions>
                    <execution>
                        <id>add-module-info-to-dependencies</id>
                        <phase>package</phase>
                        <configuration>
                            <outputDirectory>${project.build.directory}/modules</outputDirectory>
                            <modules>
                                <module>
                                    <moduleInfo>
                                        <name>md.test33.MainApp</name>
                                    </moduleInfo>
                                </module>
                                <module>
                                    <artifact>
                                        <groupId>org.openjfx</groupId>
                                        <artifactId>javafx.controls</artifactId>
                                        <version>11-ea+25</version>
                                    </artifact>
                               </module>
                                <module>
                                    <artifact>
                                        <groupId>org.openjfx</groupId>
                                        <artifactId>javafx.graphics</artifactId>
                                        <version>11-ea+25</version>
                                    </artifact>
                                </module>
                            </modules>
                        </configuration>
                        <goals>
                            <goal>add-module-info</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>create-runtime-image</id>
                        <phase>package</phase>
                        <goals>
                            <goal>create-runtime-image</goal>
                        </goals>
                        <configuration>
                            <modulePath>
                                <path>${project.build.directory}/modules</path>
                            </modulePath>
                            <modules>
                                <module>md.test33.MainApp</module>
                                <module>javafx.controls</module>
                                <module>javafx.graphics</module>
                            </modules>
                            <launcher>
                                <name>test33</name>
                                <module>md.test33.MainApp</module>
                            </launcher>
                            <compression>2</compression>
                            <stripDebug>true</stripDebug>
                            <outputDirectory>${project.build.directory}/jlink-image</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>


Но я получаю эту ошибку:

Failed to execute goal org.moditect:moditect-maven-plugin:1.0.0.Beta1:add-module-info (add-module-info-to-dependencies) on project test33: Failure to find org.openjfx:javafx.controls:jar:11-ea+25 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.moditect:moditect-maven-plugin:1.0.0.Beta1:add-module-info (add-module-info-to-dependencies) on project test33: Failure to find org.openjfx:javafx.controls:jar:11-ea+25 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
    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:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Failure to find org.openjfx:javafx.controls:jar:11-ea+25 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced
    at org.moditect.mavenplugin.util.ArtifactResolutionHelper.resolveArtifact(ArtifactResolutionHelper.java:77)
    at org.moditect.mavenplugin.util.ArtifactResolutionHelper.resolveArtifact(ArtifactResolutionHelper.java:57)
    at org.moditect.mavenplugin.add.AddModuleInfoMojo.resolveArtifactsToBeModularized(AddModuleInfoMojo.java:185)
    at org.moditect.mavenplugin.add.AddModuleInfoMojo.execute(AddModuleInfoMojo.java:113)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
    ... 20 more
Caused by: org.eclipse.aether.resolution.ArtifactResolutionException: Failure to find org.openjfx:javafx.controls:jar:11-ea+25 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced
    at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:444)
    at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:246)
    at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifact(DefaultArtifactResolver.java:223)
    at org.eclipse.aether.internal.impl.DefaultRepositorySystem.resolveArtifact(DefaultRepositorySystem.java:294)
    at org.moditect.mavenplugin.util.ArtifactResolutionHelper.resolveArtifact(ArtifactResolutionHelper.java:74)
    ... 25 more
Caused by: org.eclipse.aether.transfer.ArtifactNotFoundException: Failure to find org.openjfx:javafx.controls:jar:11-ea+25 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced
    at org.eclipse.aether.internal.impl.DefaultUpdateCheckManager.newException(DefaultUpdateCheckManager.java:231)
    at org.eclipse.aether.internal.impl.DefaultUpdateCheckManager.checkArtifact(DefaultUpdateCheckManager.java:206)
    at org.eclipse.aether.internal.impl.DefaultArtifactResolver.gatherDownloads(DefaultArtifactResolver.java:585)
    at org.eclipse.aether.internal.impl.DefaultArtifactResolver.performDownloads(DefaultArtifactResolver.java:503)
    at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:421)
    ... 29 more


Есть идеи у кого-нибудь? Или мне следует подождать, пока Java11 будет полностью выпущен, и надеяться, что кто-то добавит информацию о модуле в файлы JavaFX?


person Mathew Dusome    schedule 07.09.2018    source источник
comment
изменение зависимости на<dependency> <groupId>org.openjfx</groupId> <artifactId>javafx</artifactId> <version>11-ea+25</version> <type>pom</type> </dependency> работает? указанный тип   -  person Naman    schedule 10.09.2018
comment
Это ничего не изменило. Та же ошибка.   -  person Mathew Dusome    schedule 10.09.2018


Ответы (1)


Я добавил полный пример OpenJDK11 с OpenJFX 11 и автоматически сгенерированный modul-info.class с плагином moditect (щелкните здесь!)

Попробуй это:

Примечание. Свойство moduleName должно быть таким же, как в файле информации о модуле.

<?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>md</groupId>
    <artifactId>test33</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>test33</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <mainClass>md.test33.MainApp</mainClass>
        <moduleName>md</moduleName>
    </properties>

    <organization>
        <!-- Used as the 'Vendor' for JNLP generation -->
        <name>Your Organisation</name>
    </organization>

    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>11-ea+25</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <!-- sets up the version of Java you are running and complines the Code -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>11</release>  <!-- or <release>10</release>-->
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.ow2.asm</groupId>
                        <artifactId>asm</artifactId>
                        <version>6.2.1</version> <!-- Use newer version of ASM -->
                    </dependency>
                </dependencies>
            </plugin>
            <!-- used to make the program run -->            
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.6.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>${java.home}/bin/java</executable>
                            <arguments>
                                <argument>--module-path</argument>
                                <argument>
                                    ${project.build.directory}/modules
                                </argument> 
                                <argument>--module</argument>
                                <argument>${moduleName}/${mainClass}</argument>
                            </arguments>
                        </configuration>
                    </execution>
                </executions>

            </plugin>     

            <plugin>
              <artifactId>maven-jar-plugin</artifactId>
              <version>3.1.0</version>
              <configuration>
                 <outputDirectory>
                     ${project.build.directory}/modules
                 </outputDirectory>
              </configuration>
           </plugin>


            <plugin>
                <groupId>org.moditect</groupId>
                <artifactId>moditect-maven-plugin</artifactId>
                <version>1.0.0.Beta1</version>
                <executions>
                    <execution>
                        <id>create-runtime-image</id>
                        <phase>package</phase>
                        <goals>
                            <goal>create-runtime-image</goal>
                        </goals>
                        <configuration>
                            <modulePath>
                                <path>${project.build.directory}/modules</path>
                            </modulePath>
                            <modules>
                                <module>${moduleName}</module>
                                <!--   <module>javafx.controls</module>
                                <module>javafx.graphics</module> -->
                            </modules>
                            <launcher>
                                <name>test33</name>
                                <module>${moduleName}/${mainClass}</module>
                            </launcher>
                            <compression>2</compression>
                            <stripDebug>true</stripDebug>
                            <outputDirectory>${project.build.directory}/jlink-image</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.1.1</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/modules</outputDirectory>
                            <includeScope>runtime</includeScope>
                        </configuration>
                    </execution>
                </executions>
            </plugin> 
        </plugins>
    </build>
</project>

modul-info.java

module md { 
  requires javafx.fxml; 
  requires javafx.controls; 
  requires javafx.graphics; 
  requires javafx.base; 
  opens md.test33; 
}
person Gumara    schedule 10.09.2018
comment
получил следующее: --- moditect-maven-plugin: 1.0.0.Beta1: create-runtime-image (create-runtime-image) @ test33 --- Ошибка: модуль md.test33.MainApp не найден ---- -------------------------------------------------- ------------------ НЕИСПРАВНОСТЬ ------------------------------ ------------------------------------- Не удалось выполнить цель org.moditect: moditect-maven-plugin : 1.0.0.Beta1: create-runtime-image (create-runtime-image) в проекте test33: Выполнение create-runtime-image цели org.moditect: moditect-maven-plugin: 1.0.0.Beta1: create-runtime -image failed: не удалось выполнить jlink - ›[Справка 1] - person Mathew Dusome; 10.09.2018
comment
Есть ли в вашем проекте файл modul-info? Это должно выглядеть примерно так: module md { requires javafx.fxml; requires javafx.controls; requires javafx.graphics; requires javafx.base; requires java.logging; opens md.test33.MainApp; } - person Gumara; 10.09.2018
comment
это не плагин moditect, который должен сделать это за меня. Я создаю эту программу в netbeans и не знаю, где разместить в ней информацию о модуле. - person Mathew Dusome; 10.09.2018
comment
Я добавил в файл module-info.java и теперь смог получить его для создания jlink-изображения, но теперь программа не будет работать в netbeans, и когда я пытаюсь запустить ее за пределами, я не получаю основного атрибута манифеста в test33- 1.0-SNAPSHOT.jar - person Mathew Dusome; 10.09.2018
comment
Изменить в Netbeans: Свойства проекта - ›Действия -› Запустить проект в exec.args=--module-path ${project.build.directory}/modules --module ${moduleName}/${mainClass} - person Gumara; 10.09.2018
comment
Не удалось выполнить цель org.codehaus.mojo: exec-maven-plugin: 1.6.0: exec (default-cli) в проекте test33: параметр «исполняемый файл» отсутствует или недействителен - ›[Справка 1] - person Mathew Dusome; 10.09.2018
comment
Но если я изменю один из плагинов на: ‹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› $ {mainClass} ‹/mainClass ‹›/configuration› ‹/plugin› - person Mathew Dusome; 10.09.2018
comment
и пришлось добавить: ‹archive› ‹manifest› ‹mainClass› $ {mainClass} ‹/mainClass› ‹/manifest› ‹/archive› в плагин maven-jar-plugin для настройки основного класса - person Mathew Dusome; 10.09.2018
comment
Я попробовал сгенерированный автоматически, и он дает примерно на 45 МБ больше в jlink-изображении. Спасибо вам за помощь. - person Mathew Dusome; 12.09.2018
comment
Прошу прощения, так как с момента публикации сообщения прошло уже почти 2 года, но я использую тот же метод, и он работает нормально, пока не появится следующая ошибка: Ошибка: обнаружены две версии модуля javax.inject. Кто-нибудь может мне помочь, как это исправить? - person Nova Shadowflame; 04.06.2020
comment
Спасибо, дружище, ты спас мне жизнь :) - person Patryk Dobrowolski; 25.01.2021