xml - 为什么 eclipse 项目源目录中的 xml 文件没有复制到 target/classes 目录?

标签 xml eclipse maven buildpath eclipse-project-file

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

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

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

Could not find resource

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

最佳答案

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

但是,没有什么可以阻止您将资源文件放在其他地方,例如 src/main/java/org/wpse/db/config/,因为有些人更喜欢将资源文件与特殊包下的class文件,你只需要在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 时,它​​会为您提供以下类路径(您不想要的):

enter image description here

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

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

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

enter image description here

关于xml - 为什么 eclipse 项目源目录中的 xml 文件没有复制到 target/classes 目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12444683/

相关文章:

java - Spring 安全警告 : Class AuthorityUtils is abstract?

java - 如何修复无法解析符号 'activity_main' ?

java - Eclipse 和 Gradle 类路径导致启动缓慢

java - Maven 版本问题

java - pi4j-maven 原型(prototype)支持通过 Intellij Idea 中的 Maven

c# - 尝试使用 OOPFactory 解析使用 EligibilityBenefitDocument 的 271 个好处

java - 无法弄清楚如何显示 Android 对话框

java - 在没有 Spring Boot 或 Maven/Gradle 的情况下编写 Spring Websocket 项目

android - 从用户获取签名作为 Android (Eclipse) 中的输入

android - JWPlayer Android SDK 导入不工作