如何防止在Java FX程序中解压缩依赖项

时间:2016-10-20 17:09:09

标签: maven netbeans javafx

我在Netbeans中创建了一个新的Maven JavaFX程序(我是Java FX的新手),默认的POM尝试将依赖项解包到/target/classes目录。

这很烦人,因为我有一些非常大的依赖(即eclipse-link)。

我尝试使用copy-dependencies代替并排除大型依赖项,但它找不到类。

为什么Netbeans构建这个POM,Java FX是否需要解压缩依赖(对于FXML等)?

Unpacking C:\Users\mjmen\.m2\repository\example\automate\Automate-modbus\1.0-SNAPSHOT\Automate-modbus-1.0-SNAPSHOT.jar to C:\Users\mjmen\Documents\NetBeansProjects\Supervision\Automate\Automate-sys\target\classes with includes "" and excludes ""
Unpacking C:\Users\mjmen\.m2\repository\mysql\mysql-connector-java\5.1.40\mysql-connector-java-5.1.40.jar to C:\Users\mjmen\Documents\NetBeansProjects\Supervision\Automate\Automate-sys\target\classes with includes "" and excludes ""
Unpacking C:\Users\mjmen\.m2\repository\org\eclipse\persistence\javax.persistence\2.1.1\javax.persistence-2.1.1.jar to C:\Users\mjmen\Documents\NetBeansProjects\Supervision\Automate\Automate-sys\target\classes with includes "" and excludes ""
Unpacking C:\Users\mjmen\.m2\repository\org\glassfish\javax.json\1.0.4\javax.json-1.0.4.jar to C:\Users\mjmen\Documents\NetBeansProjects\Supervision\Automate\Automate-sys\target\classes with includes "" and excludes ""
Unpacking C:\Users\mjmen\.m2\repository\javax\validation\validation-api\1.1.0.Final\validation-api-1.1.0.Final.jar to C:\Users\mjmen\Documents\NetBeansProjects\Supervision\Automate\Automate-sys\target\classes with includes "" and excludes ""
Unpacking C:\Users\mjmen\.m2\repository\sotec\supervision\automate\Automate-model\1.0-SNAPSHOT\Automate-model-1.0-SNAPSHOT.jar to C:\Users\mjmen\Documents\NetBeansProjects\Supervision\Automate\Automate-sys\target\classes with includes "" and excludes ""
Unpacking C:\Users\mjmen\.m2\repository\org\eclipse\persistence\eclipselink\2.6.4\eclipselink-2.6.4.jar to C:\Users\mjmen\Documents\NetBeansProjects\Supervision\Automate\Automate-sys\target\classes with includes "" and excludes ""
Unpacking C:\Users\mjmen\.m2\repository\org\eclipse\persistence\commonj.sdo\2.1.1\commonj.sdo-2.1.1.jar to C:\Users\mjmen\Documents\NetBeansProjects\Supervision\Automate\Automate-sys\target\classes with includes "" and excludes ""

<?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>
    <parent>
        <artifactId>Automate</artifactId>
        <groupId>example.automate</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <groupId>example.automate</groupId>
    <artifactId>Automate-sys</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>Automate-sys</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <mainClass>example.automate.Application</mainClass>
    </properties>

    <build>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.fxml</include>
                    <include>**/*.css</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <id>unpack-dependencies</id>
                        <phase>prepare-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>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>      
                        <configuration>
                            <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.8</source>
                    <target>1.8</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>
            <plugin>
                <!-- Build an executable JAR -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.0.2</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>classes/lib/</classpathPrefix>
                            <mainClass>sotec.supervision.automate.Application</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>


    <dependencies>
        <dependency>
            <groupId>sotec.supervision.automate</groupId>
            <artifactId>Automate-model</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>sotec.supervision.automate</groupId>
            <artifactId>Automate-modbus</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>
</project>

1 个答案:

答案 0 :(得分:2)

在你的pom.xml中,找到下面的代码:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>2.6</version>
    <executions>
        <execution>
            <id>unpack-dependencies</id>
            <phase>prepare-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>
        <execution>
            <id>copy-dependencies</id>
            <phase>package</phase>
            <goals>
                <goal>copy-dependencies</goal>
            </goals>      
            <configuration>
                <outputDirectory>${project.build.directory}/classes</outputDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>

请找到元素名称<excludeGroupIds>

并添加groupId名称,您可以在<dependencies>下找到该名称。

groupId名称应以逗号(,)分隔。