提问者:小点点

无法使用 maven 和 graalvm 构建项目


我做错了什么?尝试按照此graalvm指南构建本机映像应用程序。但是我不能。

也许它在项目内部缺乏一些链接…我在IntellijIDEA工作,它说,我不能在我使用它的地方使用它。从网络搜索中我得出结论,这并不重要,但也许有我的问题?以下是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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <profiles>
        <profile>
            <id>native</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>3.1.0</version>
                        <executions>
                            <execution>
                                <id>java-agent</id>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                                <configuration>
                                    <executable>java</executable>
                                    <workingDirectory>${project.build.directory}</workingDirectory>
                                    <arguments>
                                        <argument>-classpath</argument>
                                        <classpath/>
                                        <argument>${mainClass}</argument>
                                    </arguments>
                                </configuration>
                            </execution>
                            <execution>
                                <id>native</id>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                                <configuration>
                                    <executable>${project.build.directory}/${imageName}</executable>
                                    <workingDirectory>${project.build.directory}</workingDirectory>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.graalvm.buildtools</groupId>
                        <artifactId>native-maven-plugin</artifactId>
                        <version>${native.maven.plugin.version}</version>
                        <extensions>true</extensions>
                        <executions>
                            <execution>
                                <id>build-native</id>
                                <goals>
                                    <goal>build</goal>
                                </goals>
                                <phase>package</phase>
                            </execution>
                            <execution>
                                <id>test-native</id>
                                <goals>
                                    <goal>test</goal>
                                </goals>
                                <phase>test</phase>
                            </execution>
                        </executions>
                        <configuration>
                            <fallback>false</fallback>
                            <buildArgs>
                                <arg>-H:DashboardDump=fortune -H:+DashboardAll</arg>
                            </buildArgs>
                            <agent>
                                <enabled>true</enabled>
                                <options>
                                    <option>experimental-class-loader-support</option>
                                </options>
                            </agent>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <modelVersion>4.0.0</modelVersion>

    <groupId>adianov.sergei</groupId>
    <artifactId>COVID-Risk</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>COVID-Risk</name>

    <properties>
        <native.maven.plugin.version>0.9.18</native.maven.plugin.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <junit.version>5.8.2</junit.version>
        <maven.compiler.source>${java.specification.version}</maven.compiler.source>
        <maven.compiler.target>${java.specification.version}</maven.compiler.target>
        <imageName>COVID Risking</imageName>
        <mainClass>MainApp</mainClass>
    </properties>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/org.codehaus.mojo/exec-maven-plugin -->
        <dependency>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>3.1.0</version>
        </dependency>

        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>19-ea+7</version>
        </dependency>

        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>19-ea+7</version>
        </dependency>

        <dependency>
            <groupId>org.controlsfx</groupId>
            <artifactId>controlsfx</artifactId>
            <version>11.1.1</version>
        </dependency>

        <dependency>
            <groupId>com.dlsc.formsfx</groupId>
            <artifactId>formsfx-core</artifactId>
            <version>11.5.0</version>
            <exclusions>
                <exclusion>
                    <groupId>org.openjfx</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>

    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>com.google.cloud.tools</groupId>
                <artifactId>jib-maven-plugin</artifactId>
                <version>3.1.4</version>
                <configuration>
                    <to>
                        <image>docker.io/heartofglass404/COVID_Risking</image>
                    </to>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.10.1</version>
                <configuration>
                    <source>19</source>
                    <target>19</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.8</version>
                <executions>
                    <execution>
                        <!-- Default configuration for running with: mvn clean javafx:run -->
                        <id>default-cli</id>
                        <configuration>
                            <mainClass>adianov.sergei.covidrisk/adianov.sergei.covidrisk.HelloApplication</mainClass>
                            <launcher>app</launcher>
                            <jlinkZipName>app</jlinkZipName>
                            <jlinkImageName>app</jlinkImageName>
                            <noManPages>true</noManPages>
                            <stripDebug>true</stripDebug>
                            <noHeaderFiles>true</noHeaderFiles>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

和错误:

[错误]命令执行失败。org.apachemons.exec.ExecuteException:进程退出时出现错误:1(退出值:1),位于org.apachemons.cexec.DefaultExecutor.executeInternal(DefaultExecutor.java:404),位于org.apachemons.exec.DefaultExecutior.execute(DefaultExecor.java:166),位于org.codehaus.mojo.exexec.ExecMojo.exxecuteCommandLine(ExecMojo.java:1000)(ExecMojo.java:947),地址:org.codehaus.mojo.exec.ExecMojo.execute(ExecMojo.java:471),位于org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManagement.java:137),位于org.apache.maven.lifecycle.internal.MojoExecutior.doExecute2(MojoExecutitor.java:370org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutior.java:215),位于org.apach.maven.lifecycle.internal.mojoExecutoer.execute(MovoExecutor.java:171),位于org.apache.maven.livecycle.internal.MojoExecuter.execute(Movo Executor.java.163),位于org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModelBuilder.java:81),位于org.apach.maven.lifecycle.internal.builder.singlethread.SingleThreadBuilder.build(SingleThreadBuildr.java:56),位于org.apache.maven.livecycle.internal.lifecycle.starter.execute(LifecycleStarter.java:128),位于:org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)位于org.apache.maven(DefaultMavin.java:105)位于org.pache.maven.cli.MavenClice.execute(MavenCli.java:960(DirectMethodHandleAccessor.java:104),位于org.codehaus.plexus.classworlds.launcher.launcher.launcher(launcher.java:282)的java.lang.reflect.Method.invoke(Method.java:578),位于org.codehaus.flexus.classworlds.launchr.launcher.launcher.launch Enhanced(launcher.java.282),位于:org.codehos.plexus.classworlds.launch(launcher.java:225),位于org.codehaus.plexus.classworlds.launcher.launcher.main(launcher.java:347)


共1个答案

匿名用户

为了用graalVM构建javaFX,我使用了gluonhq,看起来Gluon负责javaFX,他们说

感谢Gluon的优秀员工,他们负责了JavaFX 19的大部分工作。请查看他们的 JavaFX 长期支持服务。

我试着先修复你的复制器,但它配置了太多的maven插件,它令人困惑和笨重,所以我从gluon开始页面创建了一个干净的pom xml,然后添加了你的复制器和所需的配置。这是结果。

最重要的部分如下

<plugin>
    <groupId>com.gluonhq</groupId>
    <artifactId>gluonfx-maven-plugin</artifactId>
    <version>${gluonfx.plugin.version}</version>
    <configuration>
        <target>${gluonfx.target}</target>
        <mainClass>${main.class}</mainClass>
        <attachList>
            <list>display</list>
            <list>lifecycle</list>
            <list>statusbar</list>
            <list>storage</list>
        </attachList>
        <bundlesList>
            <list>adianov.sergei.covidrisk</list>
        </bundlesList>
        <reflectionList>
            <list>adianov.sergei.covidrisk.RootLayoutController</list>
            <list>adianov.sergei.covidrisk.PersonOverviewController</list>
            <list>adianov.sergei.covidrisk.PersonEditDialogController</list>
            <list>javafx.scene.control.Button</list>
            <list>javafx.scene.control.CheckBox</list>
            <list>javafx.scene.control.CheckMenuItem</list>
            <list>javafx.scene.control.ChoiceBox</list>
            <list>javafx.scene.control.ColorPicker</list>
            <list>javafx.scene.control.ComboBox</list>
            <list>javafx.scene.control.Menu</list>
            <list>javafx.scene.control.MenuBar</list>
            <list>javafx.scene.control.MenuButton</list>
            <list>javafx.scene.control.MenuItem</list>
            <list>javafx.scene.control.RadioMenuItem</list>
            <list>javafx.scene.control.ScrollPane</list>
            <list>javafx.scene.control.Separator</list>
            <list>javafx.scene.control.SeparatorMenuItem</list>
            <list>javafx.scene.control.Slider</list>
            <list>javafx.scene.control.SplitPane</list>
            <list>javafx.scene.control.TableView</list>
            <list>javafx.scene.control.TableColumn</list>
            <list>javafx.scene.control.TextArea</list>
            <list>javafx.scene.control.TextField</list>
            <list>javafx.scene.control.ToggleButton</list>
            <list>javafx.scene.image.ImageView</list>
            <list>javafx.scene.layout.FlowPane</list>
            <list>javafx.scene.layout.GridPane</list>
            <list>javafx.scene.layout.HBox</list>
        </reflectionList>
    </configuration>
</plugin>

一个接一个地添加这些类很烦人,否则本机图像会抛出找不到异常的类。

我尝试使用graalvm原生maven插件,但对于javafx,我们不能使用它,因为javafx需要额外的库,这些库由gluon插件覆盖,还有一件事我需要使用gluon graalvm

我使用sdkman安装gluon graalvm

sdk list java
sdk install java 22.1.0.1.r17-gln

我还有一个与编译相关的问题是“找不到库”,以修复我使用

sudo apt install libasound2-dev libavcodec-dev libavformat-dev libavutil-dev libgl-dev libgtk-3-dev libpango1.0-dev libxtst-dev

从这里找到了apt命令。老实说,我对javaFX的期望更高。很难编译并产生结果,Swing看起来更容易,即使他们说javaFX很强大。毕竟intellij还在用swing。