---
title: "部署jenkins是遇到的问题汇总。"
author: "piperzero"
date: "2013-02-20T16:01:00Z"
tags: []
slug: "jenkins"
draft: false
lastmod: "2013-02-21T20:01:47Z"
id: 1812060
url: "https://piperzero.iteye.com/blog/1812060"
---

jenkins是非常方便的自动化构建攻击，在实际使用过程中还是遇到了很多的问题。

1、jsp-api 打包问题。

用mvn编译的时候需要依赖jsp-api，但是很多时候 jsp-api在tomcat等的lib下面存在，所以当打包成war文件的时候就重复了，这个时候经常会出问题

解决办法：在mvn的pom.xml里面设置

&lt;dependency&gt;  
&lt;groupId&gt;javax.servlet&lt;/groupId&gt;  
&lt;artifactId&gt;jsp-api&lt;/artifactId&gt;  
&lt;version&gt;2.0&lt;/version&gt;  
&lt;scope&gt;provided&lt;/scope&gt;  
&lt;/dependency&gt;

最后一个参数表示是参与编译，不打包。

2、在新版jenkins每次自动构建的时候，发现不是每次都更新svn仓库

解决办法：这个是设置问题，在Check-out Strategy，例如SVN， 选择EUse svn update as much as possible, with 'svn revert' before update，表示每次进行update后进行打包。

3、自动部署到tomcat

这个需要插件支持，默认安装后是不包括这个插件的，插件的名字是[Deploy to container Plugin](http://wiki.jenkins-ci.org/display/JENKINS/Deploy+Plugin)，在插件管理里面安装一下。

然后在job的构建后操作选择deploy war/ear to a container进行配置就可以了，唯一注意一点的是相对路径。

4、在自动部署到tomcat中，第一次是成功的，第二次就会把tomcat搞死，原因还不清楚，在tomcat中有日志，表示内存泄漏，日志如下：

严重: The web application \[/mrc-web] registered the JDBC driver \[net.sf.log4jdbc.DriverSpy] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.  
2013-2-20 15:06:35 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads  
严重: The web application \[/mrc-web] appears to have started a thread named \[MySQL Statement Cancellation Timer] but has failed to stop it. This is very likely to create a memory leak.  
2013-2-20 15:06:36 org.apache.catalina.startup.HostConfig checkResources  
信息: Undeploying context \[/mrc-web]  
2013-2-20 15:06:37 org.apache.catalina.startup.HostConfig deployWAR  
信息: Deploying web application archive mrc-web.war  
2013-2-20 15:34:08 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc  
严重: The web application \[/mrc-web] registered the JDBC driver \[net.sf.log4jdbc.DriverSpy] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.  
2013-2-20 15:34:09 org.apache.catalina.startup.HostConfig checkResources

如果有人能解决顺便说一下啊，非常感谢。

最后问题没有找到解决办法，换了另一种方式，但是前提是部署tomcat的机器和jenkins在一台机器上

就是在编译后执行一段windos脚本

net stop tomcat7  
rmdir/s/q D:\\apache-tomcat-7.0.22\\webapps\\mrc-web  
del mrc-web.war  
copy C:\\progra~1\\Jenkins\\workspace\\mrc\\target\\mrc-web.war D:\\apache-tomcat-7.0.22\\webapps  
net start tomcat7

就完成了部署。

4、"WARNING: clock of the subversion server appears to be out of sync. This can result in inconsistent check out behavior."

这个在编译的时候有时候会有这个警告，主要是svn等服务器的时钟和本机的时钟有偏差，比如svn的时钟比较快，jenkins的时钟慢，当你提交svn的时候，紧接着进行jenkins构建，这个时候jenkins的svn update由于时钟原因就更新不到刚才的数据，但过了几分钟之后再进行更新的时候，超过两台机器的时间差，在次进行jenkins构建，就可以update到数据。

姐姐办法就很简单，两台机器的时间设置成一样就可以了。