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

前端 未结 1 1186
孤街浪徒
孤街浪徒 2020-12-18 09:33

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 o

相关标签:
1条回答
  • 2020-12-18 10:02

    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):

    enter image description here

    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):

    enter image description here

    0 讨论(0)
提交回复
热议问题