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.youkuaiyun.com/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.youkuaiyun.com/u011851478/article/details/51762014