首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用ModiTect生成模块信息并创建运行时镜像

使用ModiTect生成模块信息并创建运行时镜像
EN

Stack Overflow用户
提问于 2020-08-24 20:53:22
回答 1查看 512关注 0票数 0

尝试使用JLink创建运行时映像,但是:

代码语言:javascript
运行
复制
Error: automatic module cannot be used with JLink: graphviz.java

我使用的是下面的library,它只有自动模块。

我做了一些搜索,似乎可以使用ModiTect为库生成模块信息并创建运行时映像。

然而,由于我是模块的新手,我不能理解它。我想我需要一个更深入的解释,而不是在ModiTect的GitHub页面上能找到什么。

我的模块-info.java:

代码语言:javascript
运行
复制
module elitonlais {
    requires javafx.controls;
    requires javafx.fxml;
    requires graphviz.java;

    opens elitonlais to javafx.fxml;
    opens elitonlais.controller to javafx.fxml;
    opens elitonlais.model to javafx.fxml;

    exports elitonlais;
    exports elitonlais.controller;
    exports elitonlais.model;
}

我的pom文件:

代码语言:javascript
运行
复制
<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>elitonlais</groupId>
    <artifactId>minafd</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>
    <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>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.2.3</version>
        </dependency>
        <dependency>
            <groupId>guru.nidi</groupId>
            <artifactId>graphviz-java</artifactId>
            <version>0.17.0</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>11</release>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.3</version>
                <configuration>
                    <mainClass>elitonlais.App</mainClass>
                    <launcher>launch.sh</launcher>
                    <compress>2</compress>
                    <jlinkZipName>MinAFD</jlinkZipName>
                    <jlinkImageName>MinAFD</jlinkImageName>
                    <includePathExceptionsInClasspath>true</includePathExceptionsInClasspath>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.moditect</groupId>
                <artifactId>moditect-maven-plugin</artifactId>
                <version>1.0.0.Beta2</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>module-info.java</module>
                                <!--   <module>javafx.controls</module>
                                <module>javafx.graphics</module> -->
                            </modules>
                            <launcher>
                                <name>test33</name>
                                <module>module-info.java/elitonlais.app</module>
                            </launcher>
                            <compression>2</compression>
                            <stripDebug>true</stripDebug>
                            <outputDirectory>${project.build.directory}/jlink-image</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

整个项目结构:https://github.com/EMachad0/MinAFD

EN

回答 1

Stack Overflow用户

发布于 2020-08-25 02:43:53

您应该能够按照链接Adding module descriptors to existing JAR files上的文档添加它。

将以下内容添加到现有的pom.xml中,作为ModiTect的附加<execution>步骤应该可以:

代码语言:javascript
运行
复制
<executions>
    <execution>
        <!-- your existing code here -->
    </execution>
    <execution>
        <id>add-module-infos</id>
        <phase>generate-resources</phase>
        <goals>
            <goal>add-module-info</goal>
        </goals>
        <configuration>
            <outputDirectory>${project.build.directory}/modules</outputDirectory>
            <modules>
                <module>
                    <artifact>
                        <groupId>guru.nidi</groupId>
                        <artifactId>graphviz-java</artifactId>
                        <version>0.17.0</version>
                    </artifact>
                    <!-- only use one of either moduleInfo or moduleInfoSource -->
                    <moduleInfo>
                        <name>guru.nidi.graphviz</name>
                        <exports>
                            *;
                        </exports>
                        <!-- possibly other fine-tuning -->
                    </moduleInfo>
                    <!-- only use one of either moduleInfo or moduleInfoSource -->
                    <moduleInfoSource>
                        module guru.nidi.graphviz {
                            requires ...;
                            exports ...;
                            provides ...
                                with ...;
                        }
                    </moduleInfoSource>
                    <!-- or use moduleInfoFile instead of the above -->
                </module>
                <module>
                    ...
                </module>
            </modules>
        </configuration>
    </execution>
</executions>

另请注意,项目已经指定了一个自动模块名称guru.nidi.graphviz,因此您需要更改自己的module-info来要求该名称,而不是自动派生的graphviz.java

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63561465

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档