[英]How to copy a generated files from a dependency to the target of current project with maven?
I have tow maven projects resources-win
and main-exec
.I try to copy a dll file from a folder win
of resources-win
and copy it to target/classes
, then i moved to the project number 2 main-exec
and i try to copy a file 2 witch is in src/main/shcemas
and the dll file of resources-win
and paste them into target classes of the project resources-win
我已经拖走了Maven项目resources-win
和main-exec
。我尝试从resources-win
的文件夹win
中复制一个dll文件,并将其复制到target/classes
,然后我移到项目编号2 main-exec
然后尝试将文件2复制到src/main/shcemas
然后将resources-win
的dll文件粘贴到项目resources-win
目标类中
Here is the bloc of code whitch helps to copy a file to target of resources-win
: 这是代码块帮助将文件复制到resources-win
目标的块:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources01</id>
<phase>process-classes</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
<encoding>UTF-8</encoding>
<resources>
<resource>
<directory>${basedir}/src/main/win</directory>
<includes>
<include>**/*.dll</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
Here is a part of pom.xml of the project main-exec
: 这是项目main-exec
的pom.xml的一部分:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-libraries</id>
<phase>generate-resources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<!-- win32 -->
<artifactItem>
<groupId>com.resources-win</groupId>
<artifactId>ressources-win</artifactId>
<version>1.0.0-SNAPSHOT</version>
<type>pom</type>
<destFileName>xdol.dll</destFileName>
<outputDirectory>${project.build.directory}/temp/schemas</outputDirectory>
</artifactItem>
</artifactItems>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
I did like that by using an xsd file by adding to pom.xml of resources-win
: 我这样做是通过将xsd文件添加到resources-win
pom.xml中来resources-win
:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources-xsd</id>
<phase>process-classes</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
<encoding>UTF-8</encoding>
<resources>
<resource>
<directory>${basedir}/src/main/schemas</directory>
<includes>
<include>**/*.xsd</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${project.build.outputDirectory}/titi.xsd</file>
<type>xsd</type>
<classifier>titi</classifier>
</artifact>
<artifact>
<file>${project.build.outputDirectory}/toto.xsd</file>
<type>xsd</type>
<classifier>toto</classifier>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
Then into the pom.xml of main-exec
i added: 然后添加到main-exec
的pom.xml中:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-libraries</id>
<phase>generate-resources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>groupId of resources-win</groupId>
<artifactId>artifactId of resources-win</artifactId>
<version>${resources-win.version}</version>
<type>xsd</type>
<classifier>toto</classifier>
<destFileName>toto.xsd</destFileName>
<outputDirectory>${project.build.directory}/tmp/schemas</outputDirectory>
</artifactItem>
</artifactItems>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
I added also the the pom.xml of main-exec the dependency of resources-win. 我还添加了main-exec的pom.xml,它依赖资源双赢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.