`
wangyanlong0107
  • 浏览: 482379 次
  • 性别: Icon_minigender_1
  • 来自: 沈阳
社区版块
存档分类
最新评论

maven 打包时mapper.xml打不进去问题

 
阅读更多

首先,来看下MAVENx项目标准的目录结构:

<iframe id="iframe_0.6057847872536948" style="margin: 0px; padding: 0px; border-width: initial; border-style: none; width: 730px; height: 343px;" src="data:text/html;charset=utf8,%3Cstyle%3Ebody%7Bmargin:0;padding:0%7D%3C/style%3E%3Cimg%20id=%22img%22%20src=%22http://dl2.iteye.com/upload/attachment/0096/8848/d6ee84fd-c812-31a9-b309-f40941ac558c.jpg?_=5340683%22%20style=%22border:none;max-width:1576px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.6057847872536948',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no"></iframe>

一般情况下,我们用到的资源文件(各种xml,properites,xsd文件等)都放在src/main/resources下面,利用maven打包时,maven能把这些资源文件打包到相应的jar或者war里

 

有时候,比如mybatis的mapper.xml文件,我们习惯把它和Mapper.java放一起,都在src/main/java下面,这样利用maven打包时,就需要修改pom.xml文件,来把mapper.xml文件一起打包进jar或者war里了,否则,这些文件不会被打包的。(maven认为src/main/java只是java的源代码路径)。网络上有很多方法,我大概试了下,几种方法都可以,可以任选一种即可。

 

方法1,其中**/*这样的写法,是为了保证各级子目录下的资源文件被打包。

xml代码

复制代码
<build>
    <finalName>test</finalName>
    <!--
    这样也可以把所有的xml文件,打包到相应位置。
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
                <include>**/*.tld</include>
            </includes>
            <filtering>false</filtering><--这里是false,用true会报 数据库连接 错误-->
        </resource>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
                <include>**/*.tld</include>
            </includes>
            <filtering>false</filtering>
        </resource>
    </resources>
</build>
复制代码

方法2,利用build-helper-maven-plugin插件

复制代码
<build>
    ...
    </plugins>
        ...
        <!--
        此plugin可以用
        利用此plugin,把源代码中的xml文件,
        打包到相应位置,这里主要是为了打包Mybatis的mapper.xml文件 
        -->
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>1.8</version>
            <executions>
                <execution>
                    <id>add-resource</id>
                    <phase>generate-resources</phase>
                    <goals>
                        <goal>add-resource</goal>
                    </goals>
                    <configuration>
                        <resources>
                            <resource>
                                <directory>src/main/java</directory>
                                <includes>
                                    <include>**/*.xml</include>
                                </includes>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>   
        ...
    </plugins>     
    ...
</build>
复制代码

方法3,利用maven-resources-plugin插件

复制代码
<build>
    ...
    </plugins>
        ...
        <!--
        此plugin可以用
        利用此plugin,把源代码中的xml文件,打包到相应位置,
        这里主要是为了打包Mybatis的mapper.xml文件 
        -->
        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.5</version>
            <executions>
                <execution>
                    <id>copy-xmls</id>
                    <phase>process-sources</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${basedir}/target/classes</outputDirectory>
                        <resources>
                            <resource>
                                <directory>${basedir}/src/main/java</directory>
                                <includes>
                                    <include>**/*.xml</include>
                                </includes>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>   
        ...
    </plugins>     
    ...
</build>
复制代码

转载于:http://bglmmz.iteye.com/blog/2063856

分享到:
评论

相关推荐

    maven+spring+mybatis配置

    1.非web环境下spring如何与mybatis集成 2.maven如何打可以直接运行的jar包 3.maven如何用profile动态打包jdbc.properties 4.maven如何把mybatis的mapper.xml一起打包到jar中

    springMVC+Spring+Mybatis+Maven整合代码案例

    一、准备工作 1、工具:jdk1.7.0_80(64)+tomcat7.0.68+myeclipse10.6+mysql-5.5.48-win32 2、 开发环境安装配置、Maven项目创建(参考:...8、测试三个框架的整合:Maven编译打包部署服务器,测试。

    springboot+mybatis+内置tomcat示例.rar

    内容1:spingboot打包成 jar包 内置 tomcat 直接可以运行,out\artifacts 点 startup.bat ,maven,直接下载动态库 jdk1.8 64位。 内置 log4j2 日志文件,每天生成日志 application.properties 配置如下 #静态...

    SpringMVC-Mybatis-Shiro-redis-master 权限集成缓存中实例

    打包的时候,不同版本的 Eclipse 还有IDEA 会有打包打不进去Mapper.xml 文件,这个时候要加如下代码(群里同学提供的)。 &lt;directory&gt;src/main/java **/*.properties **/*.xml &lt;filtering&gt;false ...

    Nacos2.2版本数据库适配插件.zip

    可参考nacos-postgresql-datasource-plugin-ext工程,新创建Maven项目,实现AbstractDatabaseDialect类,重写相关的分页操作逻辑与方法,并创建相应的mapper实现,减少了适配的成本。 目前对于Oracle、达梦数据库,...

    单点登录源码

    不涉及业务的纯粹的支付平台。 - 统一下单(统一下单接口、统一扫码)、订单管理、数据分析、财务报表、商户管理、渠道管理、对账系统、系统监控。 ![统一扫码支付](project-bootstrap/zheng-pay.png) &gt; zheng-...

    基于SSM+Mysql实现的CRM信息管理系统源码+数据库+项目说明.zip

    * 本系统通过Maven来进行环境的搭建,Maven的依赖,我已经打包好了,在根目录的tree.txt目录下,也可以通过pom文件来进行查看。 * 文件的目录如下: &lt;img src="/img/src.png" &gt; * main项目下是项目的主要实现...

    java8源码-mult:多线程应用

    打包项目 启动tomcat 目录结构描述 &gt; ├── Readme.md // help &gt; ├── pom.xml // maven配置文件 &gt; ├── LICENSES // 开源协议 &gt; ├── .gitignore // git忽略文件列表 &gt; ├── resources // 静态资源 &gt; │ ...

    基于SpringBoot的图书馆管理系统源码+数据库+项目说明(毕设).zip

    | mapper:数据库SQL语句mapper文件 &emsp;&emsp;| static:静态文件 &emsp;&emsp;&emsp;&emsp;| css:css文件 &emsp;&emsp;&emsp;&emsp;| js:JavaScript文件 &emsp;&emsp;&emsp;&emsp;| images:...

    基于SpringBoot的图书馆管理系统项目源码+数据库+项目说明(课程设计).zip

    | mapper:数据库SQL语句mapper文件 &emsp;&emsp;| static:静态文件 &emsp;&emsp;&emsp;&emsp;| css:css文件 &emsp;&emsp;&emsp;&emsp;| js:JavaScript文件 &emsp;&emsp;&emsp;&emsp;| images:...

    MTime:时光网-基于spring boot的影评网站

    部署到服务器也是非常简单的使用maven打包上传服务器后执行命令java -jar 项目包名.jar即可 到现在为止spring boot做的都只是替换spring mvc的作用,没有进行封装并不是真正意义上的微服务,后续将会改。 Author ...

    spring-boot-plus后台框架-其他

    4、快速生成后台代码: entity/param/vo/controller/service/mapper/xml 5、集成Swagger/Knife4j,可自动生成api文档 6、集成jwt、shiro权限控制 7、集成Redis缓存 8、集成HikariCP连接池,JDBC性能和慢查询检测 9、...

    J2eeFAST企业级快速开发平台-其他

    3、编译代码找到根目录下pom.xml,执行mvn clean install命令编译一键打包。一般来说不会有什么问题,如果还是编译不成功,可以按照优先级逐个编译试一试。4、导入数据库db目录里initDb.sql有建库建表语句按步骤执行...

Global site tag (gtag.js) - Google Analytics