【问题标题】:why xml files in eclipse project's source directory is not copied to target/classes directory?为什么 Eclipse 项目的源目录中的 xml 文件没有复制到 target/classes 目录?
【发布时间】:2012-09-08 19:24:51
【问题描述】:

这个问题与MyBatis 3.0.5 and mappers loading problemHow to suppress Maven "Unable to find resource" messages?不一样

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

当我使用 mybatis 时,这个错误会导致以下失败:

Could not find resource

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

【问题讨论】:

  • 这个包在哪里 - 在src/main/javasrc/main/resources

标签: xml eclipse maven buildpath eclipse-project-file


【解决方案1】:

Maven 默认在src/main/resources 目录中查找资源文件,即*.xml、*.properties 等。建议把你的资源文件放在这里。

但是,没有什么能阻止您将资源文件放在其他地方,例如src/main/java/org/wpse/db/config/,因为有些人喜欢将资源文件与类文件一起放在特殊的包下,您只需要在 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>

相关问题: how to customize maven to generate the .classpath that i want?

默认配置下,运行mvn eclipse:eclipse时会生成如下的.classpath文件:

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

当导入 Eclipse 时,它​​会为您提供以下类路径(您不想要的):

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

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

当导入 Eclipse 时,它​​会为您提供以下类路径(您想要的):

【讨论】:

    猜你喜欢
    • 2014-02-15
    • 1970-01-01
    • 2016-02-27
    • 1970-01-01
    • 2012-08-04
    • 1970-01-01
    • 1970-01-01
    • 2018-12-15
    • 1970-01-01
    相关资源
    最近更新 更多