1
我要在项目的根某些文件(JAR,启动脚本,文件)拷贝到某个目录,比如dist/
。Maven,如何复制文件?
我正在使用maven-assembly-plugin并在pom.xml中设置了<configuration><outputDirectory>
。它在dist/
但里面<my_project>-<decsriptor_id>/
子目录下创建文件。
有什么办法来输出它只是在dist/
根源在哪里?
还是有在Maven的是简单的拷贝文件的插件吗?
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>maven-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<outputDirectory>${project.basedir}/dist</outputDirectory>
<descriptors>
<descriptor>${project.basedir}/src/main/maven-assembly/dist.xml</descriptor>
</descriptors>
</configuration>
</plugin>
dist.xml
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<id>dist</id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<files>
<file>
<source>path........</source>
<fileMode>0755</fileMode>
<outputDirectory>.</outputDirectory>
</file>
</files>
</assembly>
你告诉插件目录下创建一个以' DIR ',所以你为什么惊讶地有它在输出?做一个ZIP,看看有没有基本目录这里(因为'假 includeBaseDirectory>'),只是格式的结果。你试图完成什么任务?和文件永远不要向外界比'target'其它地方创建(所以'<输出目录> $ {} project.basedir/DIST输出目录>'是不是一个好主意)。 –
Tunaki
只是为了方便起见,将所有需要的文件(来自不同的地方)放在一个目录中,而没有其他目标。为什么这不是一个好主意? – AlexP11223
只是因为你的src文件夹在版本控制之下,这意味着你在生成过程中用生成的文件污染了它......默认情况下应该排除目标文件夹,因此目标文件夹是包含生成的东西的默认目录(如编译类,编译测试等,以及创建的zip文件或jar文件)....这就是为什么它不是一个好主意的原因... – khmarbaise