如何阻止Maven在每个项目运行中解压缩

时间:2017-04-13 17:52:40

标签: java hibernate maven netbeans javafx

我有一个使用Hibernate ORM并拥有Maven的JavaFX项目。每次当我运行我的项目时,我都要等待它运行,因为Maven一直在解包Hibernate依赖项。这至关重要吗?或者我可以把它关掉,为什么要一次又一次地解开所有东西而不是一次?日志看起来像这样:

  

--- maven-dependency-plugin:2.6:unpack-dependencies(unpack-dependencies)@ SeedCalendar ---   解压缩C:\ Users \ maurice.m2 \ repository \ org \ hibernate \ javax \ persistence \ hibernate-jpa-2.1-api \ 1.0.0.Final \ hibernate-jpa-2.1-api-1.0.0.Final.jar to C:\ book \ SeedCalendar \ target \ classes with includes""并且不包括""   解压缩C:\ Users \ maurice.m2 \ repository \ org \ hibernate \ hibernate-core \ 5.2.9.Final \ hibernate-core-5.2.9.Final.jar到C:\ book \ SeedCalendar \ target \ classes with includes ""并且不包括""   将C:\ Users \ maurice.m2 \ repository \ org \ javassist \ javassist \ 3.20.0-GA \ javassist-3.20.0-GA.jar打包到包含"的C:\ book \ SeedCalendar \ target \ classes "并且不包括""   将C:\ Users \ maurice.m2 \ repository \ antlr \ antlr \ 2.7.7 \ antlr-2.7.7.jar打包到C:\ book \ SeedCalendar \ target \ classes,其中包含""并且不包括""   将C:\ Users \ maurice.m2 \ repository \ com \ fasterxml \ classmate \ 1.3.0 \ classmate-1.3.0.jar打包到C:\ book \ SeedCalendar \ target \ classes,其中包含""并且不包括""   将C:\ Users \ maurice.m2 \ repository \ dom4j \ dom4j \ 1.6.1 \ dom4j-1.6.1.jar打包到C:\ book \ SeedCalendar \ target \ classes,其中包含""并且不包括""   将C:\ Users \ maurice.m2 \ repository \ org \ jboss \ jandex \ 2.0.3.Final \ jandex-2.0.3.Final.jar解压缩到包含"的C:\ book \ SeedCalendar \ target \ classes "并且不包括""   将C:\ Users \ maurice.m2 \ repository \ org \ jboss \ logging \ jboss-logging \ 3.3.0.Final \ jboss-logging-3.3.0.Final.jar解压缩到C:\ book \ SeedCalendar \ target \ classes包括""并且不包括""   解压缩C:\ Users \ maurice.m2 \ repository \ org \ jboss \ spec \ javax \ transaction \ jboss-transaction-api_1.2_spec \ 1.0.1.Final \ jboss-transaction-api_1.2_spec-1.0.1.Final。 jar到C:\ book \ SeedCalendar \ target \ classes with includes""并且不包括""   将C:\ Users \ maurice.m2 \ repository \ org \ hibernate \ common \ hibernate-commons-annotations \ 5.0.1.Final \ hibernate-commons-annotations-5.0.1.Final.jar解压缩到C:\ book \ SeedCalendar \ target \ classes with includes""并且不包括""   --- exec-maven-plugin:1.2.1:exec(unpack-dependencies)@ SeedCalendar ---   javafxpackager.exe已重命名为javapackager.exe。   原始文件可能会在将来的版本中删除,而不是javapackager。   请更新您的脚本。

我的POM文件如下所示:

<?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.hibernate</groupId>
<artifactId>SeedCalendar</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>SeedCalendar</name>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <mainClass>com.hibernate.seedcalendar.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.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.9.Final</version>

    

任何人都可以一步一步地告诉我如何关闭这个恼人的功能,如果关闭这个自动解压缩模式会有什么不好的影响吗?

谢谢你!

2 个答案:

答案 0 :(得分:2)

我找到了解决自己问题的方法,让我解释一下。

问题与javafxpackager无关。原因在于maven标准配置。在每个项目运行中,Maven默认执行项目清理。这会删除targets / classes /文件夹。这是放置依赖项的所有解压缩jar文件的同一文件夹。如果在每次新的运行中都删除了那些,那么必须一遍又一遍地解压缩它们。无论如何,继承人如何防止干净发生:

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

将此添加到您的POM.xml。确保你的版本正确你可以在有效的pom中检查你的maven clean插件的版本(那就是父pom +项目POM的组合)。在netbeans中,当您打开项目的pom.xml文件时,可以在有效选项卡下查看只读有效的pom.xml。

从来不知道解决方案是这个简单的pffff ..

编辑:

您需要进行另一次调整,以避免跳过标记引起的错误。请将一个Skip命令添加到default-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>

编辑2:另一种方法是防止maven删除你的jar文件,同时保留在netbeans中使用Clean的能力。

<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>

答案 1 :(得分:0)

我在POM文件中找到了

<executable>${java.home}/../bin/javafxpackager</executable>

所以改为

<executable>${java.home}/../bin/javapackager</executable>

并且一切似乎都运作良好。