这个问题和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 时,它会为您提供以下类路径(您不想要的):
使用上面的 pom 配置,当运行“mvn eclipse:eclipse”时,它会生成以下 .classpath 文件:
<classpath>
<classpathentry kind="src" path="src/main/java"/>
... ...
</classpath>
... ...
当导入 Eclipse 时,它会为您提供以下类路径(您想要的):
关于xml - 为什么 eclipse 项目源目录中的 xml 文件没有复制到 target/classes 目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12444683/