Maven does not copy non-java files

南楼画角 提交于 2019-12-01 14:32:50

问题


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?


回答1:


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.




回答2:


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)



来源:https://stackoverflow.com/questions/8314715/maven-does-not-copy-non-java-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!