maven 打war包及出现各种问题及解决办法

maven打war包步骤:

1.右键项目选择Run as或者Debug as后maven clean

1.右键项目选择Run as或者Debug as后maven install

maven打war包过程中出现错误(编译不通过):

一.符号找不到,不存在(编译不通过)
    Maven报错Please ensure you are using JDK 1.4 or above and not a JRE解决方法
    解决:
    原因1:eclipse默认是使用jre作为运行环境,而maven编译需要jdk作为运行环境
    因此,我们只要设置为jdk即可。
    1)http://blog.csdn.net/u011851478/article/details/51762014
    原因2:
    2)jdk版本必须与右键项目的properties中的projet facets中的Java对应版本一致且与本机exlipse配置的运行环境jdk版本一致

二.解决maven无法加载本地lib/下的jar包问题(程序包XXX不存在)(编译不通过)

解决办法:
若该程序包是jdk自带的程序包,请参照:解决maven编译错误:程序包com.sun.xxx不存在
若该程序包是第三方的jar,解决方案是让maven既加载maven库中的jar包,又要加载本地WEB-INF/lib下的jar包。


如果报错maven 编译出错Fatal error compiling: 无效的目标发行版: 1.8,看看以下jdk的版本是否一致

注意:
1.如果你的jdk是1.7则<source>和<target>改为1.7
若你的jdk是1.6则<source>和<target>改为1.7
2.项目中pom.xml中的jdk配置版本要与maven安装目录中的jdk版本一致

解决办法

1.在pom.xml文件中的<build>标签中添加下面一段配置:

<plugins>
	<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <encoding>UTF-8</encoding>
                    <compilerArguments>
                        <extdirs>${project.basedir}/src/main/webapp/WEB-INF/lib</extdirs>
                    </compilerArguments>
                </configuration>
         </plugin>
</plugins>
2.修改maven全局jdk
修改 安装目录\maven2\conf\settings.xml
<profile>       
               <id>jdk-1.7</id>       
               <activation>       
                   <activeByDefault>true</activeByDefault>       
                   <jdk>1.7</jdk>       
               </activation>       
               <properties>       
                   <maven.compiler.source>1.7</maven.compiler.source>       
                   <maven.compiler.target>1.7</maven.compiler.target>       
                   <maven.compiler.compilerVersion>1.7</maven.compiler.compilerVersion>       
               </properties>       
</profile>
若该程序包是tomacat下的jar包,则
1.将tomcat安装目录下的lib文件夹下的servlet-api.jar引入到maven项目的lib下并build path
2.右键项目properties中的Java build path中保证添加server环境tomcat
3.Maven项目下HttpServletRequest 或 HttpServletResponse需引用的依赖包:servlet-api.jar,并将scope设置为provided。
pom.xml中的<dependencies>的标签中添加

中的<profiles>标签中加入

<dependency>
	     <groupId>javax.servlet</groupId>
	     <artifactId>servlet-api</artifactId>
	     <version>2.5</version>
	     <scope>provided</scope>
</dependency>
三.若出现不能解析resources配置文件中的com/xxx/xxx/*mapper.xml
解决办法:
在spring配置文件中配置解析mapper文件处classpath后面记得加上*

<property name="mapperLocations" value="classpath*:com/cn/xxx/mapper/*Mapper.xml"></property>


参考博客地址:http://blog.csdn.net/u011851478/article/details/51762014


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值