为什么eclipse项目的源目录中的xml文件没有复制到目标/ classes目录? [英] why xml files in eclipse project's source directory is not copied to target/classes directory?

查看:266
本文介绍了为什么eclipse项目的源目录中的xml文件没有复制到目标/ classes目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题与 MyBatis 3.0.5和映射器加载问题如何抑制Maven无法找到资源消息?

我在org.org.wpse.db.config.db.config包中有xml文件,但为什么我找不到这些xml文件target / classes / org / wpse / db / config /目录,即使我运行mvn编译。

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.

当我使用mybatis时,此错误导致以下faillure:

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

Could not find resource

导致此错误的问题是.xml文件不会复制到构建目录,即使我使用mvn编译显式

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

推荐答案

默认情况下,Maven在 src / main / resources 目录中查找资源文件,即* .xml,* .properties等。建议将资源文件放在这里。

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.

但是,没有什么可以阻止您将资源文件放在别的地方,例如 src / main / java / org / wpse / db / config / ,因为有些人喜欢把资源文件与class文件一起放在特殊的包中,你只需要在pom.xml中更多的配置:

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>






相关问题: 如何自定义maven以生成.classpath我想要?

默认配置,当运行 mvn eclipse:eclipse 它会生成以下.classpath文件:

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

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

当导入到Eclipse中时,它会提供以下类路径(你不想要什么):

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

使用上面的pom配置,当运行'mvn eclipse:eclipse'时,它会生成以下.classpath文件:

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

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

当导入到Eclipse中时,它会为您提供类路径你想要什么):

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

这篇关于为什么eclipse项目的源目录中的xml文件没有复制到目标/ classes目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆