2016-11-24 61 views
0

我拖Maven项目resources-winmain-exec。我试图从一个文件夹的resources-winwin复制一个DLL文件,并将其复制到target/classes,然后我搬到了项目编号2 main-exec和我尝试复制文件2女巫是在src/main/shcemasresources-win的DLL文件,并将其粘贴到项目resources-win如何使用maven将生成的文件从依赖项复制到当前项目的目标?

这里的目标是类代码的集团whitch有助于将文件复制到目标的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> 

下面是该项目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> 
+0

我认为你的方式是错误的:首先,将你的DLL文件放在src/main/resources下,因为它是一个项目资源,然后在'main-exec'中有一个real' '''ressources-win'(你不需要'maven-dependency-plugin')。然后,您可以像访问其他资源一样访问它。 – Tunaki

+0

它是我们公司的一个项目,所以我不能把它放在任何地方 – TinyOS

+0

什么是不工作?什么都不复制?复制错误的地方? – JFPicard

回答

0

我不喜欢通过使用XSD文件加入到resources-win的pom.xml:

<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> 

然后到POM的main-exec .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> 

我还加的pom.xml中主exec的资源双赢的依赖。

相关问题