pedr0
pedr0

Reputation: 3011

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?

Upvotes: 10

Views: 13991

Answers (2)

CoolBeans
CoolBeans

Reputation: 20800

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.

Upvotes: 14

digitaljoel
digitaljoel

Reputation: 26574

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)

Upvotes: 1

Related Questions