spring、mybatis、tomcat打包找不到xml(mapping或者resource下的xml)

这个问题 主要是maven的基础知识。

一、maven中pom打包。

pom的目录结构

|-- pom.xml
`-- src
    |-- main
    |   |-- java
    |   |   `-- com
    |   |       `-- mycompany
    |   |           `-- app
    |   |               `-- App.java
    |   `-- resources
    |           `-- db.properties
                --- spring.xml
    `-- test
        `-- java
            `-- com
                `-- mycompany
                    `-- app
                        `-- AppTest.java

打包之后 (大概的意思)

--WEB-INF
    --classes  
        --com
            --mycompany
        --spring.xml
        --db.properties
    --lib
    web.xml

<resources> 标签

<resources> 标签位于 <build> 标签内,用于指定项目资源文件的位置。例如,我们有一个 configuration.xml 文件,我们的项目要求这个文件位于 META-INF/plexus 中,虽然我们可以将其放置在 src/main/resource/META-INF/plexus 中,但我们给了这个文件自己的目录 src/main/plexus ,为了将其正确地打包进 jar 中,我们可以使用如下的配置
 

<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                      https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <build>
    ...
    <resources>
      <resource>
        <targetPath>META-INF/plexus</targetPath>
        <filtering>false</filtering>
        <directory>${basedir}/src/main/plexus</directory>
        <includes>
          <include>configuration.xml</include>
        </includes>
        <excludes>
          <exclude>**/*.properties</exclude>
        </excludes>
      </resource>
    </resources>
    <testResources>
      ...
    </testResources>
    ...
  </build>
</project>
  • resources:资源文件列表
  • targetPath:放置资源文件的目录,默认是根路径
  • filtering:是否过滤资源文件
  • directory:资源文件所在目录
  • includes:需要包含的文件列表
  • excludes:需要排除的文件列表
  • testResources:测试资源文件列表,配置类似 resources

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值