有代码更新后重新打包到tomcat再发布,是不是很烦?
看了下面的东西你就不会烦了。
SVN或者git等代码版本控制工具不说了,如果是本地开发,也可以安装一个svn server端
jenkins下载后是一个war包,
首先设置下 环境变量 JENKINS_HOME 为 c:\jenkins
拷贝到一个tomcat的webapp目录下启动tomcat保证能正常访问
http://localhost:8880/jenkins/ 多个tomcat请注意修改端口
打开后第一次没任何项目,新建一个项目 maven项目,怎么创建maven项目 请参考我的博客其他文章
必填项:
项目名称: 随意了,自己喜欢就好 O(∩_∩)O哈哈~
下面填写自己的svn cvs等信息,地址及用户名密码
往下: 请勾选 Build whenever a SNAPSHOT dependency is built 这个复选框
再往下就是配置构建成功后发布信息的,这个首先得安装一个插件
安装Deploy to container Plugin 插件,安装成功后才能自动发布
安装好后重启下服务器最好
构建后操作,选择安装好插件后的 deploy war to container,
输入target目录下生成的war包,
配置远程的tomcat,并保证可以登录到manage界面,配置的tomcat处于启动状态
注意:
tomcat默认是没有用户可以登录的 需要修改 conf下的user.xml
如下:
<?xml version=‘1.0‘ encoding=‘utf-8‘?><tomcat-users> <role rolename="manager-gui"/> <role rolename="manager-script"/> <role rolename="manager-jmx"/> <role rolename="manager-status"/> <user password="tomcat" roles="manager-gui,manager-script,manager-jmx,manager-status" username="tomcat"/></tomcat-users>
同时记得修改tomcat/conf/context.xml
<Context antiResourceLocking="true">
修改这个主要是为了解决再次部署的时候,不能删除原项目部署目录,详情可参考 http://tomcat.apache.org/tomcat-7.0-doc/config/context.html 搜索 lock
配置完成,点击应用 保存
然后创建,失败是红色,具体信息看控制台,成功后的log大致如下:
Started by user anonymous Building in workspace c:\jenkins\workspace\demo Updating https://xiaochangwei/svn/demo1/Test001 at revision ‘2015-11-10T12:59:10.009 +0800‘ At revision 7 no change for https://xiaochangwei/svn/demo1/Test001 since the previous build Parsing POMs Established TCP socket on 51539 [demo] $ "C:\Program Files\Java\jdk1.7.0_80/bin/java" -cp c:\jenkins\plugins\maven-plugin\WEB-INF\lib\maven32-agent-1.7.jar;C:\work\software\apache-maven-3.3.3\boot\plexus-classworlds-2.5.2.jar;C:\work\software\apache-maven-3.3.3/conf/logging jenkins.maven3.agent.Maven32Main C:\work\software\apache-maven-3.3.3 C:\apache-tomcat-7.0.64\webapps\jenkins\WEB-INF\lib\remoting-2.52.jar c:\jenkins\plugins\maven-plugin\WEB-INF\lib\maven32-interceptor-1.7.jar c:\jenkins\plugins\maven-plugin\WEB-INF\lib\maven3-interceptor-commons-1.7.jar 51539 <===[JENKINS REMOTING CAPACITY]===>channel started Executing Maven: -B -f c:\jenkins\workspace\demo\pom.xml install [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Test001 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Test001 --- [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent! [INFO] Copying 0 resource [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ Test001 --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ Test001 --- [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent! [INFO] Copying 0 resource [INFO] [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ Test001 --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ Test001 --- [JENKINS] Recording test results [INFO] [INFO] --- maven-war-plugin:2.2:war (default-war) @ Test001 --- [INFO] Packaging webapp [INFO] Assembling webapp [Test001] in [c:\jenkins\workspace\demo\target\Test001-0.0.1-SNAPSHOT] [INFO] Processing war project [INFO] Copying webapp resources [c:\jenkins\workspace\demo\src\main\webapp] [INFO] Webapp assembled in [41 msecs] [INFO] Building war: c:\jenkins\workspace\demo\target\Test001-0.0.1-SNAPSHOT.war [INFO] WEB-INF\web.xml already added, skipping [INFO] [INFO] --- maven-install-plugin:2.4:install (default-install) @ Test001 --- [INFO] Installing c:\jenkins\workspace\demo\target\Test001-0.0.1-SNAPSHOT.war to c:\wis_mvn_repo\com\xiao\Test001\0.0.1-SNAPSHOT\Test001-0.0.1-SNAPSHOT.war [INFO] Installing c:\jenkins\workspace\demo\pom.xml to c:\wis_mvn_repo\com\xiao\Test001\0.0.1-SNAPSHOT\Test001-0.0.1-SNAPSHOT.pom [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 3.192 s [INFO] Finished at: 2015-11-10T12:59:18+08:00 [INFO] Final Memory: 17M/226M [INFO] ------------------------------------------------------------------------ [JENKINS] Archiving c:\jenkins\workspace\demo\pom.xml to com.xiao/Test001/0.0.1-SNAPSHOT/Test001-0.0.1-SNAPSHOT.pom [JENKINS] Archiving c:\jenkins\workspace\demo\target\Test001-0.0.1-SNAPSHOT.war to com.xiao/Test001/0.0.1-SNAPSHOT/Test001-0.0.1-SNAPSHOT.war channel stopped [WARNING] Couldn‘t clean up oid=3 from null hudson.remoting.ChannelClosedException: channel is already closed at hudson.remoting.Channel.send(Channel.java:575) at hudson.remoting.RemoteInvocationHandler$PhantomReferenceImpl.cleanup(RemoteInvocationHandler.java:360) at hudson.remoting.RemoteInvocationHandler$PhantomReferenceImpl.access$700(RemoteInvocationHandler.java:319) at hudson.remoting.RemoteInvocationHandler$Unexporter.run(RemoteInvocationHandler.java:420) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask.run(FutureTask.java:262) at hudson.remoting.AtmostOneThreadExecutor$Worker.run(AtmostOneThreadExecutor.java:110) at java.lang.Thread.run(Thread.java:745) Caused by: java.io.IOException at hudson.remoting.Channel.close(Channel.java:1160) at hudson.remoting.Channel.close(Channel.java:1135) at hudson.remoting.Channel$CloseCommand.execute(Channel.java:1076) at hudson.remoting.Channel$1.handle(Channel.java:498) at hudson.remoting.SynchronousCommandTransport$ReaderThread.run(SynchronousCommandTransport.java:60) Deploying c:\jenkins\workspace\demo\target\Test001-0.0.1-SNAPSHOT.war to container Tomcat 7.x Remote [c:\jenkins\workspace\demo\target\Test001-0.0.1-SNAPSHOT.war] is not deployed. Doing a fresh deployment. Deploying [c:\jenkins\workspace\demo\target\Test001-0.0.1-SNAPSHOT.war] Finished: SUCCESS
打开tomcat管理页面都能看见发布的项目
同样打开这个项目也能正常访问
jdk maven配置:
如果遇见编码问题
1.增加环境变量 JAVA_TOOL_OPTIONS= -Dfile.encoding=UTF-8
2.在kenkins中增加Environment variables LANG=zh.CH.UTF-8 和 JAVA_TOOL_OPTIONS= -Dfile.encoding=UTF-8
原文地址:http://fangwei009.blog.51cto.com/5234706/1977933