当前位置: 首页 > 知识库问答 >
问题:

如何阻止Maven在每次项目运行时解包

太叔天宇
2023-03-14

我有一个JavaFX项目,它使用Hibernate ORM和Maven。每次运行项目时,我都要等待很长时间才能运行,因为Maven一直在解包Hibernate依赖项。这是必要的吗?或者我可以关掉它,为什么要一遍又一遍地打开所有东西而不是只打开一次?日志如下所示:

我的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个答案

令狐和裕
2023-03-14

我已经为自己的问题找到了解决办法,让我来解释。

这个问题与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文件时,您可以在effective选项卡下查看只读有效的pom.xml。

                    <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>
 类似资料:
  • 我使用的是 Maven 3.1.1。在我的一个项目中,我引用了我的另一个项目...... 以上依赖于我的其他几个项目。但是,当我运行“mvn 全新安装”时,Maven 会尝试下载这些项目,而不仅仅是使用本地存储库中的内容。如何让 Maven 仅在我的本地存储库中不存在内容时才下载这些内容?这是我所看到的输出...

  • 上周,我们的团队决定从Netbean迁移到Eclipse,因为我们开发了一些只能在Eclipse上运行的新插件。 首先,项目开始使用来自pom的my maven插件

  • 我在docker中用这样的命令启动了jenkins: docker run-p 8080:8080-p50000:50000--restart总是jenkins/jenkins: lts-jdk11 尝试使用命令docker kill get response停止它无法杀死容器::权限被拒绝 同时尝试停止容器也会被拒绝权限。

  • 本文向大家介绍详解如何运行vue项目,包括了详解如何运行vue项目的使用技巧和注意事项,需要的朋友参考一下 在师兄的推荐下入坑vue.js ,发现不知如何运行GitHub上的开源项目,很尴尬。通过查阅网上教程,成功搭建好项目环境,同时对前段工程化有了朦朦胧胧的认知,因此将环境搭建过程分享给大家。 可以看下我的github:https://github.com/padipata ,里面有我学习、工作

  • 我需要在docker中运行selenium测试用例。我引用的多篇文章都是一样的。我可以在docker中运行测试用例,它只设置了selenium。但我的项目是maven build,我想在docker中运行。 项目设置: 使用Java的Selenium webdriver 我从几篇有用的文章中了解到: 需要创建测试用例jar 但是我无法使这个设置工作。

  • 我刚刚开始Spring Boot并设法在PostgreSQL数据库中创建表。然后,我将一个配置文件添加到我的项目中,该文件将把数据插入数据库。但是,据我所见,代码并没有命中这个配置文件并重新创建表。我试图更改文件中的参数,但这没有任何意义,结果,在运行空记录的每个应用程序上重新创建表(在Java控制台just create table上也可以看到)。那么,我错过了什么? 应用程序.属性: 学生配置