Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何加快JavaFX应用程序的maven构建?_Java_Spring_Maven_Netbeans_Javafx - Fatal编程技术网

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

如何加快JavaFX应用程序的maven构建?,java,spring,maven,netbeans,javafx,Java,Spring,Maven,Netbeans,Javafx,通过在Netbeans 8中创建一个新项目,可以重现我的问题: 新项目>>Maven>>JavaFX应用程序 然后添加org.springframework-spring上下文依赖项 构建时间从几秒钟增加到半分钟以上,大部分是由于运行javafxpackager 我可以接受慢发布版本,但如何加快开发版本 这是我的pom.xml: <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.

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

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

然后添加org.springframework-spring上下文依赖项

构建时间从几秒钟增加到半分钟以上,大部分是由于运行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>

4.0.0
com.mycompany
mavenproject1
1.0-快照
罐子
mavenproject1
UTF-8
com.mycompany.mavenproject1.MainApp
您的组织
org.apache.maven.plugins
maven依赖插件
2.6
解包依赖项
包裹
解包依赖项
系统
junit,org.mockito,org.hamcrest
${project.build.directory}/classes
org.codehaus.mojo
execmaven插件
1.2.1
解包依赖项
包裹
执行官
${java.home}/./bin/javafxpacker
-createjar
-nocss2bin
-应用类
${mainClass}
-srcdir
${project.build.directory}/classes
-奥特迪尔
${project.build.directory}
-外锉
${project.build.finalName}.jar
默认cli
执行官
${java.home}/bin/java
${runfx.args}
org.apache.maven.plugins
maven编译器插件
3.1
1.7
1.7
${sun.boot.class.path}${path.separator}${java.home}/lib/jfxrt.jar
org.apache.maven.plugins
maven surefire插件
2.16
${java.home}/lib/jfxrt.jar
org.springframework
spring上下文
4.0.6.1发布

谢谢!
Daniel

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

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


...
org.codehaus.mojo
execmaven插件
...
...
...
javafxpackager

在生产运行中
mvn-Pjavafxpackager

为了完成Nikos的回答,这是maven assembly插件的配置,它为正常构建创建了存档

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <configuration>
        <appendAssemblyId>false</appendAssemblyId>
        <archive>
            <manifest>
                <mainClass>${mainClass}</mainClass>
            </manifest>
        </archive>
        <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
    </configuration> 
    <executions>
        <execution>
            <id>my-assembly</id>
            <phase>package</phase>
            <goals>
                <goal>assembly</goal>
            </goals>
        </execution>
    </executions>
</plugin>

org.apache.maven.plugins
maven汇编插件
假的
${mainClass}
带有依赖项的jar
我的集会
包裹
装配

上述解决方案不起作用。这个问题与javafxpackager没有任何关系。原因在于maven标准配置。默认情况下,在每个项目运行时,Maven都执行项目清理。这将删除目标/类/文件夹。这就是您的依赖项的所有未打包jar文件所在的文件夹。如果在每次新的运行中删除这些文件,那么它们必须一次又一次地解压缩。无论如何,以下是防止清洁发生的方法:

    <plugin>
  <artifactId>maven-clean-plugin</artifactId>
  <version>2.4.1</version>
  <configuration>
    <skip>true</skip>
  </configuration>
</plugin>

maven清洁插件
2.4.1
真的
将此添加到POM.xml中。确保版本正确,您可以在有效的pom中检查maven clean插件的版本(即父pom+项目pom的组合)。在netbeans中,当您打开项目的pom.xml文件时,您可以在effective选项卡下查看readonly effective pom.xml

请给我一些+1,我想得到50分,这样我就可以最终对其他人的答案发表评论。谢谢大家!

编辑:

还将跳过添加到默认cli以避免错误

                <execution>
                    <id>default-cli</id>
                    <goals>
                        <goal>exec</goal>                            
                    </goals>
                    <configuration>
                                <skip>true</skip>
                        <executable>${java.home}/bin/java</executable>
                        <commandlineArgs>${runfx.args}</commandlineArgs>
                    </configuration>
                </execution>

默认cli
执行官
真的
${java.home}/bin/java
${runfx.args}
编辑2:

对于那些希望保留清理功能的人,这里有另一种方法来防止maven插件删除所有jar文件:

<plugin>
<artifactId>maven-clean-plugin</artifactId>
     <version>2.4.1</version>
<configuration>
    <excludeDefaultDirectories>true</excludeDefaultDirectories>
    <filesets>
        <!-- delete directories that will be generated when you 
             start the develpment server/client in eclipse  
        -->
        <fileset>
            <directory>target/classes</directory>
            <excludes>
                <exclude>**/*</exclude>
            </excludes>
        </fileset>
    </filesets>
</configuration>

maven清洁插件
2.4.1
真的
目标/类别
**/*

同样,请确保是正确的

<
mvn -T 4 install -- will use 4 threads
mvn -T 1C install -- will use 1 thread per available CPU core