With maven - clean package, xml source files are not included in classpath

不羁的心 提交于 2019-11-28 09:41:57

By default maven does not include any files from "src/main/java" (${sourceDirectory} variable). You have two possibilities (choose one of them):

  • put all your resource files (different than java files) to "src/main/resources" - recomended
  • Add to your pom (example from gwt plugin):

    <build>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>                      
                    <include>**/*.xml</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
        </resources>
    </build>
    

The xml file shouldn't be placed in src/main/java but in src/main/resources instead. Maven will only compile java sources in src/main/java and will ignore everything else in there by default.

If you want to keep the XML in src/main/java, you can add it in the resource section of the POM. I would recommend against this, try to keep non-java files that you want in the artifact in src/main/resources.

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