Antonio
Antonio

Reputation: 1654

maven antrun copy resources to base target directory

I'm learning how to use maven for my standalone java apps but I don't understand how to do a recursive copy of all directories from /src/main/resources to /taget directory.

I tried using antrun and resources plugin, but resources are copied to /target/classes and not to /target.

What is wrong here?

<build>
  <pluginManagement><plugin>
     <artifactId>maven-antrun-plugin</artifactId>
     <version>1.4</version>
     <executions>
      <execution>
       <phase>process-resources</phase>
       <configuration>
        <tasks>
         <copy todir="${basedir}/target">
          <fileset dir="${basedir}/src/main/resources" includes="**/*" />
         </copy>
        </tasks>
       </configuration>
       <goals>
        <goal>run</goal>
       </goals>
      </execution>
     </executions>
    </plugin>  </pluginManagement>
 </build>

Thanks for your help.

EDIT: I would copy to /target directories like "bin","logs","conf", so I can test the app. and, with another maven task, package everything (jars and bin/conf/tmp dirs) into a zip/tar.gz file.

Upvotes: 9

Views: 30544

Answers (3)

You can use copy todir to do this using maven-antrun-plugin

<tasks>
    <mkdir dir="${basedir}/target/folder"/>
    <copy todir="${basedir}/target/folder">
        <fileset dir="${basedir}/src/folder" includes="**/*" />
    </copy>
</tasks>

Upvotes: 2

Adrian Shum
Adrian Shum

Reputation: 40036

I think you are using maven in a wrong way.

Normall you don't need to "copy" resources to target. It is done by maven automatically already.

If you have some extra resources that is needed in testing, you can add

<build>
   <testResources>
        <testResource>
            <directory>${basedir}/src/test/anotherKindOfResourceDir</directory>
        </testResource>
    </testResources>
<build>

And, as told by lexicore, you are not suppose to use pluginManagement. "pluginManagement", just like "dependencyManagement", provides a "template" when project really use that plugin/ have that dependency. That means, adding pluginManagement/dependencyManagement won't trigger any plugin / won't add any dependency to your project.

Upvotes: 1

lexicore
lexicore

Reputation: 43651

  • Try with <plugins ... /> instead of <pluginManagement ... />.
  • Copying things to target to test it feels a bit weird. Will you run maven every time you need to test your application?

Upvotes: 5

Related Questions