web-dev-qa-db-ja.com

moditectおよびJava 11を使用したJavaFX Maven

に従って maven-jlink-pluginの使用中にmavenの依存関係を追加する方法はありますか? 誰かがJavaFXで ModiTect Mavenプラグイン を使用しています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

他の投稿を読んで、モジュール情報を生成する必要があることはわかっていますが、誰かがpomでModiTect Mavenプラグインを使用して、毎回自動的にそれを実行することを望んでいました。

私はすべてのプログラムで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ファイルにモジュール情報を追加することを願うべきでしょうか?

7
Mathew Dusome

OpenJFX11を使用したOpenJDK11の完全な例と、moditectプラグインを使用して自動生成されたmodul-info.classを追加しました( here !をクリックします)。

これを試して:

注: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; 
}
5
Gumara