2

I have a JavaFX project that uses Hibernate ORM and has Maven. Each time when i Run my project i have to wait ages for it to run because Maven keeps unpacking Hibernate dependencies. Is this essential? Or can i turn it off, why would have to unpack everything over and over again instead of just once? The log looks like this:

--- maven-dependency-plugin:2.6:unpack-dependencies (unpack-dependencies) @ SeedCalendar --- Unpacking 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 "" and excludes "" Unpacking C:\Users\maurice.m2\repository\org\hibernate\hibernate-core\5.2.9.Final\hibernate-core-5.2.9.Final.jar to C:\book\SeedCalendar\target\classes with includes "" and excludes "" Unpacking C:\Users\maurice.m2\repository\org\javassist\javassist\3.20.0-GA\javassist-3.20.0-GA.jar to C:\book\SeedCalendar\target\classes with includes "" and excludes "" Unpacking C:\Users\maurice.m2\repository\antlr\antlr\2.7.7\antlr-2.7.7.jar to C:\book\SeedCalendar\target\classes with includes "" and excludes "" Unpacking C:\Users\maurice.m2\repository\com\fasterxml\classmate\1.3.0\classmate-1.3.0.jar to C:\book\SeedCalendar\target\classes with includes "" and excludes "" Unpacking C:\Users\maurice.m2\repository\dom4j\dom4j\1.6.1\dom4j-1.6.1.jar to C:\book\SeedCalendar\target\classes with includes "" and excludes "" Unpacking C:\Users\maurice.m2\repository\org\jboss\jandex\2.0.3.Final\jandex-2.0.3.Final.jar to C:\book\SeedCalendar\target\classes with includes "" and excludes "" Unpacking C:\Users\maurice.m2\repository\org\jboss\logging\jboss-logging\3.3.0.Final\jboss-logging-3.3.0.Final.jar to C:\book\SeedCalendar\target\classes with includes "" and excludes "" Unpacking 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 to C:\book\SeedCalendar\target\classes with includes "" and excludes "" Unpacking C:\Users\maurice.m2\repository\org\hibernate\common\hibernate-commons-annotations\5.0.1.Final\hibernate-commons-annotations-5.0.1.Final.jar to C:\book\SeedCalendar\target\classes with includes "" and excludes "" --- exec-maven-plugin:1.2.1:exec (unpack-dependencies) @ SeedCalendar --- javafxpackager.exe has been renamed javapackager.exe. The original file may be removed in a future release in lieu of javapackager. Please update your scripts.

My POMfile looks like this:

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

Can anyone tell me step by step how to turn this annoying feature off and if there will be any bad repercussions when turning this auto-unpack mode off?

thank you!

Maurice
  • 6,698
  • 9
  • 47
  • 104
  • 1
    since isnt a behavior built in to maven - this was explicitly requested by your build (the unpack-dependencies execution) - so question is why does your build need this done at all to begin with? – radai Apr 13 '17 at 17:56
  • i dont know, i dident tamper with the POMfile myself i just let Netbeans create a standard JavaFX Maven project. Which part should i remove in order to make the unpacking carnage stop? – Maurice Apr 14 '17 at 07:19
  • The problem is simply based on the misunderstanding of the concept of Maven...but than starting to try to script something...which results in simply bad build...unpack-dependencies is in majority of the cases an indication of such misunderstanding...It would had been better to use exec:java goal of exec-maven-plugin cause it has already all deps on the classpath...so...To clean that up you need to fully understand the whole build and than you can clean it up...and make it correctly work... – khmarbaise Apr 14 '17 at 11:56
  • indeed, i don't know anything about maven other then it autodownloads your desired JAR files. Could you please tell me what part of my POM file needs to be removed or changed for the autounpacking to stop? thank you – Maurice Apr 14 '17 at 18:25
  • it seems Ant likes to auto-add libraries of obsolete Hibernate libraries whilst ignoring the most recent hibernate jar files that i added. I am a total newbie at Maven. Could someone please tell me how to make it unpack once? I have already tried to remove the unpack dependencies part from the POM file, but that only results in a maven compile error. Please help.. I'm unable to program my project any further because of this issue. – Maurice Apr 18 '17 at 16:56
  • i also tried this solution: http://stackoverflow.com/questions/25135775/how-can-i-speed-up-maven-builds-of-javafx-application/25227720 but it doesen't seem to work either. – Maurice Apr 18 '17 at 17:11

2 Answers2

6

I have found the solution for my own problem, let me explain.

The problem has nothing to do with javafxpackager whatsoever. The cause lies in the maven standard configuration. On every project run Maven performs a project clean by default. This deletes the targets/classes/ folder. Thats the same folder where all the unpacked jar files of your dependencies are placed. If those get deleted on every new run then they have to be unpacked over and over again. Anyway, heres how you can prevent the clean from happening:

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

Add this to your POM.xml. Make sure you get the version correct You can check the version of your maven clean plugin in the effective pom (thats parent pom + project POM combined). In netbeans you can watch the readonly effective pom.xml under the effective tab when you've opened the pom.xml file of your project.

Never knew the solution was this easy pffff..

EDIT:

You need to make another adjustment in order to avoid errors caused by skip tag. Please add a Skip command to the configurations part of default-cli as well like this:

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

EDIT 2: Heres another way to prevent maven from deleting your jar files while retaining the ability to use Clean in 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>

Maurice
  • 6,698
  • 9
  • 47
  • 104
  • not visible somehow... make sure to check f – Maurice Apr 22 '17 at 21:06
  • It would be even easier in NetBeans to simply change the project properties. By default NetBeans commands the clean on the 'Run Project' and 'Debug Project' Actions. Changing the POM just works around the command executed by NetBeans. – shawn1874 Sep 08 '19 at 22:48
0

I found in the POM file

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

So changed to

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

and all seems to work well.

depicus
  • 301
  • 4
  • 19
  • That does fix a warning, but has nothing to do with the question. Using the other packager has nothing to do with this issue. – shawn1874 Sep 08 '19 at 22:48