why xml files in eclipse project's source directory is not copied to target/classes directory?

强颜欢笑 提交于 2019-11-28 01:21:54

问题


this issue is not the same as MyBatis 3.0.5 and mappers loading problem and How to suppress Maven "Unable to find resource" messages?

i have xml files in org.org.wpse.db.config.db.config package, but why i cannot find these xml files in target/classes/org/wpse/db/config/ directory even after i run mvn compile.

this error leads to the following faillure when i use mybatis:

Could not find resource

the issue which lead to this error is that the .xml files are not copied to the build dir, even i when i used mvn compile explicitly


回答1:


Maven is by default looking for resource files i.e. *.xml, *.properties and etc. in src/main/resources directory. It is recommended to put your resource files under here.

However, nothing prevent you from putting resource files somewhere else, for instance, src/main/java/org/wpse/db/config/, as some people prefer to put resource files along with class file under special package, you just need a little more configuration in pom.xml:

<build>
  <resources>
    <resource>
      <!-- This include everything else under src/main/java directory -->
      <directory>${basedir}/src/main/java</directory>
      <excludes>
        <exclude>**/*.java</exclude>
      </excludes>
    </resource>
  </resources>

  ... ...
</build>

Related question: how to customize maven to generate the .classpath that i want?

By default configuration, when running mvn eclipse:eclipse it generates following .classpath file:

<classpath>
  <classpathentry kind="src" path="src/main/java" including="**/*.java"/>
  ... ...
</classpath>
... ...

When importing into Eclipse, it gives you following classpath (what you don't want):

Using the pom configuration above, when running 'mvn eclipse:eclipse' it generates following .classpath file:

<classpath>
  <classpathentry kind="src" path="src/main/java"/>
  ... ...
</classpath>
... ...

When importing into Eclipse, it gives you follwing classpath (what you want):



来源:https://stackoverflow.com/questions/12444683/why-xml-files-in-eclipse-projects-source-directory-is-not-copied-to-target-clas

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