Maven-删除生成的文件夹 [英] Maven - Remove Generated Folders

查看:966
本文介绍了Maven-删除生成的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用maven-compiler插件生成我的.jar

I'm using the maven-compiler plugin to generate my .jar

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>

当我进行全新安装时,除了我的.jar之外,它还会生成诸如"generated-sources","maven-archiver","maven-status"和"classes"之类的文件夹

When I do a clean install it will generate folders such as "generated-sources", "maven-archiver", "maven-status" amd "classes" in addition to my .jar

在安装后如何自动删除这些文件夹,或者阻止生成这些文件夹?

How could I automatically deleted those folders after the install or prevent them from being generated?

推荐答案

您不能阻止生成这些文件夹,因为它们对于构建工作至关重要. generated-sources最有可能包含Java源代码,该Java源代码是在构建过程中生成的,并且需要其他代码进行编译; classes包含在src/main/java下的已编译Java源代码,用于生成后续的JAR或WAR等.因此,如果没有这些文件夹,则该构建将无法正常工作.

You cannot prevent those folders from being generated as they are essential to making the build work. generated-sources most likely contains Java source code that was generated during the build and is needed to make the rest of the code compile; classes contains the compiled Java source code that was under src/main/java and is needed to make a subsequent JAR or WAR, etc. So, without those folders, the build cannot properly work.

但是,它们本质上是暂时的.实际上,整个target文件夹都是临时的.它包含在构建时生成/复制的数据,这些数据是生成最终工件所必需的.这就是为什么在构建Maven项目之前始终clean通常是一个好主意的原因:它确保清除此构建文件夹,以便创建新的新数据(否则,它可能依赖于旧的构建数据,从而可能使工作变得困难来跟踪错误).

However, they are inherently temporary. In fact, the whole target folder is temporary. It contains data that is generated / copied at build-time and is needed to make the final artifacts. This is why it is generally a good idea to always clean before building a Maven project: it makes sure that this build folder is cleaned so that new fresh data is created (otherwise, it might rely on old build data, potentially making hard to track down bugs).

创建最终工件后,它们将是安装或部署项目时唯一要考虑的工件.如果您真的想在构建后删除那些文件(但我不明白为什么),则可以始终运行mvn clean install clean.安装项目的工件后,这将删除target文件夹.

Once the final artifacts are created, they will be the only one to be considered when installing or deploying the project. If you really want to get rid of those files after the build (but I don't see why), you could always run mvn clean install clean. This will delete the target folder once the project's artifacts are installed.

这篇关于Maven-删除生成的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆