Maven : copy files without subdirectory structure

前端 未结 2 1504
醉话见心
醉话见心 2020-12-08 14:39

I am trying to use Maven to move all the *.xsd files contained in a given folder to another one, but without the source subdirectory structure.

This is what I have s

相关标签:
2条回答
  • 2020-12-08 15:24

    I banged my head against that restriction myself, again and again.

    Basically: I don't think there's a maven only solution. You will have to resort to using something dynamic like

    • The Maven Antrun Plugin
      Embed ant tasks in maven, in this case an ant copy task, something like this:

      <copy todir="${project.basedir}/schemas-target" flatten="true">
          <fileset dir="${project.basedir}/schemas-source">
              <include name="**/*.xsd"/>
          </fileset>
      </copy>
      
    • The GMaven plugin Lets you execute Groovy code from your pom, something like this:

      new File(pom.basedir, 'schemas-source').eachFileRecurse(FileType.FILES){
          if(it.name.endsWith('.xsd')){
              new File(pom.basedir, 'schemas-target/${it.name}').text = it.text;
          }
      }
      
    0 讨论(0)
  • 2020-12-08 15:35

    There is a way.. and its really monotonous and cumbersome. Implement it only if you want to be completely mavenized. Sean's answer is the easiest solution.

    The problem is you have to specify each and every directory and then use wild cards for the files inside.

    <execution>
    <id>copy-jars</id>
    <phase>process-sources</phase>
    <goals>
        <goal>copy-resources</goal>
    </goals>
    <configuration>
        <outputDirectory>${basedir}/target/classes</outputDirectory>
        <resources>
            <resource>
                <directory>${basedir}/resources</directory>
                <includes>
                    <include>xyz.jar</include>
                </includes>
            </resource>     
            <resource>
                <directory>${basedir}/as-u-like-it</directory>
                <includes>
                    <include>abc.jar</include>
                </includes>
            </resource>     
    </configuration>
    

    0 讨论(0)
提交回复
热议问题