当前位置: 首页 > 面试题库 >

如何加快JavaFX应用程序的Maven构建?

乜安志
2023-03-14
问题内容

我的问题可以通过在Netbeans 8中创建一个新项目来重现:

新项目>> Maven >> JavaFX应用程序

然后添加org.springframework spring-context依赖项。

构建时间从几秒钟增加到超过半分钟,这大部分是由于运行javafxpackager引起的。

我可以使用缓慢发布的版本,但是如何加快开发版本?

这是我的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     http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.mycompany</groupId>
<artifactId>mavenproject1</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>mavenproject1</name>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <mainClass>com.mycompany.mavenproject1.MainApp</mainClass>
</properties>

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

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.6</version>
            <executions>
                <execution>
                    <id>unpack-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>unpack-dependencies</goal>
                    </goals>
                    <configuration>
                        <excludeScope>system</excludeScope>
                        <excludeGroupIds>junit,org.mockito,org.hamcrest</excludeGroupIds>
                        <outputDirectory>${project.build.directory}/classes</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <executions>
                <execution>
                    <id>unpack-dependencies</id>

                    <phase>package</phase>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                    <configuration>
                        <executable>${java.home}/../bin/javafxpackager</executable>
                        <arguments>
                            <argument>-createjar</argument>
                            <argument>-nocss2bin</argument>
                            <argument>-appclass</argument>
                            <argument>${mainClass}</argument>
                            <argument>-srcdir</argument>
                            <argument>${project.build.directory}/classes</argument>
                            <argument>-outdir</argument>
                            <argument>${project.build.directory}</argument>
                            <argument>-outfile</argument>
                            <argument>${project.build.finalName}.jar</argument>
                        </arguments>
                    </configuration>
                </execution>
                <execution>
                    <id>default-cli</id>
                    <goals>
                        <goal>exec</goal>                            
                    </goals>
                    <configuration>
                        <executable>${java.home}/bin/java</executable>
                        <commandlineArgs>${runfx.args}</commandlineArgs>
                    </configuration>
                </execution>
            </executions>  
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
                <compilerArguments>
                    <bootclasspath>${sun.boot.class.path}${path.separator}${java.home}/lib/jfxrt.jar</bootclasspath>
                </compilerArguments>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.16</version>
            <configuration>
                <additionalClasspathElements>
                    <additionalClasspathElement>${java.home}/lib/jfxrt.jar</additionalClasspathElement>
                </additionalClasspathElements>
            </configuration>
        </plugin>
    </plugins>
</build>
<dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>4.0.6.RELEASE</version>
    </dependency>
</dependencies>

谢谢!丹尼尔


问题答案:

您可以在默认情况下处于非活动状态的配置文件中定义插件。然后,为了进行生产构建,您将必须手动指定该配置文件的激活(或以任何其他标准方式激活它)。

您的pom类似于(仅显示差异):

<?xml version="1.0" encoding="UTF-8"?>
<project ...>
    ...
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                ...
                <executions>
                    <!-- take this out of here
                    <execution>
                        <id>unpack-dependencies</id>
                        ...
                    </execution>
                    -->
                    <execution>
                        ...
                    </execution>
                </executions>
            </plugin>
            ...
        </plugins>
    </build>
    <profiles>
        <profile>
            <id>javafxpackager</id>
            <build>
                <plugins>
                    <!-- INSERT THE exec-maven-plugin HERE, ONLY
                         WITH THE unpack-dependencies EXECUTION -->
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

在生产运行中 mvn ... -Pjavafxpackager



 类似资料:
  • 我是JavaFX新手。我使用Maven创建了一个Hello World项目。当我在Eclipse中运行时,它工作得很好。 当我试图使用build.fxbuild构建应用程序时,我得到了这个错误。

  • 问题内容: 我正在尝试使用Gradle构建相对简单的JavaFX应用程序。但是,我不知道该怎么做。 我是Gradle的新手,对于简单的(非javafx)项目,我已经成功使用了插件,并构建和打包了库和命令行应用程序。 但是,关于JavaFX,我完全陷入困境。我已经阅读了这篇文章,该文章建议使用该插件,但是我只能找到该插件的源代码,但是没有关于如何实际使用它的文档(在文章中,他们只是从远程URL应用它

  • 我试图使用Gradle构建一个相对简单的JavaFX应用程序。但是,我完全不知道该怎么做。 我对Gradle比较陌生,对于简单的(非JavaFX)项目,我已经成功地使用了插件和来构建和打包库和命令行应用程序。 然而,当涉及到JavaFX时,我完全被卡住了。我读过这篇文章,其中建议使用插件,但是我只能找到这个插件的源代码,而没有关于如何实际获取它和使用它的文档(在文章中,他们只是从远程URL应用它,

  • 问题 当JavaFX应用程序被打包为Jar文件时,我应该怎么做才能在JavaFX应用程序中加载资源? 出身背景 该应用程序是IntelliJ IDEA中的一个Maven项目。直接从IntelliJ运行应用程序对于下面描述的所有情况都很好,但是我从项目中构建的jar文件大多无法加载资源(图像和字体)。 项目目录树 加载图像的工作原理如下: 但是,因为我实际上想加载图像文件夹中的所有图像,而无需硬编码

  • 我是詹金斯的新手,运气不太好。我正在尝试用maven构建我的spring boot应用程序。它成功地构建,直到我在调用顶级Maven目标中添加命令“clean compile package”。 构建失败。 我该如何解决这个问题?

  • 问题:从Eclipse IDE运行基于Maven非模块项目(project name=“howdyJFX”)的JavaFX应用程序会生成以下编译错误: 开发环境和配置: null 上面的配置和代码是基于“入门”指南和Sr.Jose Pereda的Github帖子,以及对去年9月提出的类似问题的回答。然而,不管出于什么原因,我不能让这个工作。这更令人沮丧,因为我正在完成一个大量的JFX控件库,这些控