Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven does not copy non-java files

I have a pom.xml file with the following:

<sourceDirectory>${basedir}/src/main/test</sourceDirectory>
<outputDirectory>${basedir}/src/main/bin </outputDirectory>

Inside ${basedir}/src/main/test I have some folders which do not contain any .java files. When I start a compilation they are not copied to ${basedir}/src/main/bin directory.

Only .java files are moved (after compilation of course) and stored on the right folder.

Can someone help me to solve this problem without using any plugin ?

I tried with

<resources>
        <resource>
            <filtering>false</filtering>
             <directory>${basedir}/src/main/test/scenarios</directory>
             <includes>
                <include>*.xml</include>
             </includes>
             <targetPath>${basedir}/src/main/bin/scenarios</targetPath>
        </resource>

        <resource>
            <filtering>false</filtering>
             <directory>${basedir}/src/main/test/sut</directory>
             <includes>
                <include>*.xml</include>
             </includes>
             <targetPath>${basedir}/src/main/bin/sut</targetPath>
        </resource>

    </resources>

But it does not work. What is wrong?

like image 772
pedr0 Avatar asked Nov 29 '11 17:11

pedr0


People also ask

Which plugin is used to copy filter include and exclude non Java files?

Apache Maven Resources Plugin – Including and excluding files and directories.

What command can you use to run the compile goal of the compiler plugin?

As both goals of the compiler plugin are automatically bound to phases in the Maven default lifecycle, we can execute these goals with the commands mvn compile and mvn test-compile.


2 Answers

You can add src/main/test as a resource directory using the maven resources plugin. see http://maven.apache.org/plugins/maven-resources-plugin/examples/resource-directory.html for basic information and http://maven.apache.org/plugins/maven-resources-plugin/examples/include-exclude.html for information on only including certain files (since you won't want to copy your .java files)

like image 35
digitaljoel Avatar answered Sep 18 '22 19:09

digitaljoel


If they are not java files you should move them to the src/main/resources and/or src/test/resources directory. That's the maven convention for storing the non java files.

Your other option is to use the maven-resources-plugin.

  <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.3</version>
        </plugin>
    </plugins>
    <resources>
        <resource>
        <directory>src/main/test</directory>
            <includes>
                <include> <the_files_you_want_to_include></include>
            </includes>
        </resource>
    </resources>

You have another option is to use the maven-antrun-plugin and execute an ant task to copy the files manually.

like image 148
CoolBeans Avatar answered Sep 19 '22 19:09

CoolBeans