2017-04-13 29 views
0

我有一个使用Hibernate ORM并具有Maven的JavaFX项目。每当我运行我的项目时,我必须等待其运行时间,因为Maven会继续解包Hibernate依赖项。这是必不可少的?或者我可以关闭它,为什么不得不一遍又一遍地打开所有东西,而不是一次?日志看起来是这样的:如何阻止Maven在每个项目运行时解包

--- Maven的依赖关系的插件:2.6:解开依赖性(解压依赖性)@ SeedCalendar --- 开箱C:\用户\ maurice.m2 \库\组织\ hibernate \ javax \ persistence \ hibernate-jpa-2.1-api \ 1.0.0.Final \ hibernate-jpa-2.1-api-1.0.0.Final.jar到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 with includes“”并排除“” Un打包C:\ Users \ maurice.m2 \ repository \ antlr \ antlr \ 2.7.7 \ antlr-2.7.7.jar到C:\ book \ SeedCalendar \ target \ classes with includes“”并排除“” 解包C: \ Users \ maurice.m2 \ repository \ com \ fasterxml \ classmate \ 1.3.0 \ classmate-1.3.0.jar到C:\ book \ SeedCalendar \ target \ classes with includes“”并排除“” 开箱C:\ Users \ maurice.m2 \ repository \ dom4j \ dom4j \ 1.6.1 \ dom4j-1.6.1.jar到C:\ book \ SeedCalendar \ target \ classes with includes“”并排除“” 开箱C:\ Users \ maurice .m2 \ repository \ org \ jboss \ jandex \ 2.0.3.Final \ jandex-2.0.3.Final.jar到C:\ book \ SeedCalendar \ target \ classes with includes“”并排除“” 开箱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 with includes“”并排除“” 开箱C:\ Users \ maurice.m2 \ rep ository \ 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 \包含“”的类并排除“” 开箱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。 请更新您的脚本。

我POMfile看起来是这样的:

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

谁能告诉我一步一步如何把这个恼人的功能关闭,是否会有任何不良后果什么时候关闭自动解包模式?

谢谢!

+1

因为不是maven内置的行为 - 这是你的构建(解包 - 依赖性执行)明确要求的 - 所以问题是为什么你的构建需要这样做呢? – radai

+0

我不知道,我偶然篡改了POM文件,我自己让Netbeans创建了一个标准的JavaFX Maven项目。我应该删除哪部分以便进行拆箱大屠杀? – Maurice

+0

这个问题只是基于对Maven概念的误解......但是开始尝试编写脚本......这导致了简单的糟糕构建...解压缩依赖关系在大多数情况下表明了这样的情况误解......最好是使用exec:java目标exec-maven-plugin,因为它已经在类路径中全部重复了...所以...要清理它,你需要完全理解整个构建,比你可以清理它...并使其正确工作... – khmarbaise

回答

1

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

这个问题与javafxpackager无关。原因在于Maven标准配置。在每个项目运行时,Maven默认执行项目清理。这会删除目标/类/文件夹。这就是放置依赖项的所有解压缩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 ..

编辑:

您需要再拍调整,以避免因跳过标记错误。请以默认的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:下面有另一种方式来防止行家从删除您的jar文件,同时保留了NetBeans使用清洁的能力。

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

+0

不知何故...请务必检查f 是否正确 – Maurice

0

我在POM文件

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

发现所以改为

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

和所有似乎运作良好。