怎么将jenkins远程部署war打包后的war自动部署到jetty上

在jetty中部署jenkins
参考上一篇部署jetty环境 http://my.oschina.net/longfirst/blog/699398 另外,需要补充下,在该环境下,使用service jetty start启动服务后,运行的用户是root,如何将运行用户改为非root用户呢? 添加如下配置到/etc/default/jetty中 JETTY_USER=jetty JETTY_SHELL=/bin/bash 重新启动服务,即可。 如果碰到启动失败,可以去目录/opt/web/mybase/logs中查看日志,可以删除该目录下的日志重新启动 比如碰到这样的报错: Caused by: java.io.IOException: Cannot write log file /opt/web/mybase/logs/.stderrout.log 启动后,可以将jenkins.war复制到/opt/web/mybase/webapps目录下 这个时候打开http://ip:8080/jenkins报错,浏览器显示 HTTPERROR:503 Problemaccessing/jenkins/.Reason: ServiceUnavailable ------------ PoweredbyJetty 可以通过以下方法解决, 在/opt/web/mybase/webapps新建Jenkins.xml 添加如下配置:
/jenkins /jenkins.war Test Realm/etc/realm.properties
重新启动jetty服务,再次在浏览器中访问http://ip:8080/jenkins应该能正常使用了。 欢迎使用愉快
最新教程周点击榜
微信扫一扫2156人阅读
tomcat(2)
Jenkins(9)
因为手动部署好麻烦,要先在eclipse更新代码,然后build一下,再把target下生成的war包复制到tomcat的webapps下,启动tomcat。
首先需要下载一个Jenkins的插件:&,可以在Jenkins的系统管理-&插件管理-&可选插件中查找
安装完成后重启Jenkins,在增加构建后操作步骤中会多出一个选项Deploy war/ear to a container。
首先新建一个任务,只需要配置代码获取方式,build命令和部署war包配置即可。
1.代码获取,我们是用SVN方式获取代码的。
2.build命令。
3.war包部署。
WAR/EAR files:输入war包的相对路径,如我的war包在新建目录的target下
context path:输入用来访问tomcat的名称,localhost:8080/p**
add container:增加容器,一般选tomcat 7X就可以。这里的username与password需要到tomcat的conf文件夹中的tomcat-users.xml修改。tomcat URL就是你希望把war包部署到的tomcat所在IP地址,最后面不需要再加斜杠/。
tomcat-users.xml中的用户名及密码默认是注释掉的,所以需要删除注释,也可以直接复制以下代码到&/tomcat-users&之前。如果只是删除注释的话好像部署不会成功,还需要增加manager开头的三个role才可以。
&role rolename=&tomcat&/&
&role rolename=&role1&/&
&role rolename=&manager-gui& /&
&role rolename=&manager-script& /&
&role rolename=&manager-status& /&
&user username=&tomcat& password=&tomcat& roles=&tomcat&/&
&user username=&both& password=&tomcat& roles=&tomcat,role1&/&
&user username=&role1& password=&tomcat& roles=&role1&/&
&user username=&deploy& password=&tomcat& roles=&manager-gui,manager-script,manager-status& /&
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:17321次
排名:千里之外
原创:32篇
(1)(1)(2)(5)(2)(3)(2)(2)(3)(11)(1)在Jetty中部署Jenkins - 推酷
在Jetty中部署Jenkins
Jenkins是一个用Java编写的开源持续集成工具,是在2010年之后从Hudson中fork出来的项目,这次fork的原因是社区和Oracle公司之间的一些商标争论。目前已经有许多开源项目使用Jenkins做持续集成(当然一些其他的开源项目也有很多使用Jenkins),其中不乏一些非常著名的项目,如:
OpenStack: https://jenkins.openstack.org/ (很壮观的,里面有各种测试项目、测试机器、测试报告等)
Apache: https://builds.apache.org/ (这个也很壮观哦)
KDE: http://build.kde.org/
Jenkins: https://ci.jenkins-ci.org/ (当然Jenkins自己CI工具也是Jenkins了,哈哈)
在参与测试的OpenStack项目中,我们也用Jenkins在内部搭建了持续集成环境,主要用于 Nova/Quantum/Ceilometer 等几个子项目的持续集成。
原来搭建时,还是直接用”java -jar jenkins.war”类似这样(当然作为daemon)来执行的。今天,主要是简单了解了一下将Jenkins放到Jetty这样的Java Servlet container中运行。在搭建环境过程中遇到过几个小问题,也顺便记录一下吧。
1. Jetty 9.0.3 启动时的错误:
[root@kvm-guest jetty-9.0.3]# java -jar start.jar
Exception in thread &main& java.lang.UnsupportedClassVersionError: org/eclipse/jetty/start/Main : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: org.eclipse.jetty.start.Main. Program will exit.
原因:Jetty 9 需要 JVM 1.7 的支持(我原来的JVM是1.6)
解决方案:使用Java 1.7即可。
2. 将jenkns.war复制到webapp目录后,启动Jetty,但jenkins访问出错,HTTP ERROR 503。
启动和关闭Jetty的命令为:
[root@kvm-guest jetty-9.0.3]# java -jar start.jar -DSTOP.PORT=8881 -DSTOP.KEY=magic --daemon &
[root@kvm-guest jetty-9.0.3]# java -jar start.jar -DSTOP.PORT=8881 -DSTOP.KEY=magic --stop
在浏览器中访问时,遇到的错误信息如下:
HTTP ERROR: 503
Problem accessing /jenkins/. Reason:
Service Unavailable
------------
Powered by Jetty
查看Jetty的log中,可以看到如下的错误信息:
2013-05-21 14:33:31.265:WARN:oejuc.AbstractLifeCycle:main: FAILED org.eclipse.jetty.security.ConstraintSecurityHandler@70188b41: java.lang.IllegalStateException: No LoginService for org.eclipse.jetty.security.authentication.FormAuthenticator@790bb6f4 in org.eclipse.jetty.security.ConstraintSecurityHandler@70188b41
java.lang.IllegalStateException: No LoginService for org.eclipse.jetty.security.authentication.FormAuthenticator@790bb6f4 in org.eclipse.jetty.security.ConstraintSecurityHandler@70188b41
at org.eclipse.jetty.security.authentication.LoginAuthenticator.setConfiguration(LoginAuthenticator.java:67)
at org.eclipse.jetty.security.authentication.FormAuthenticator.setConfiguration(FormAuthenticator.java:131)
at org.eclipse.jetty.security.SecurityHandler.doStart(SecurityHandler.java:375)
at org.eclipse.jetty.security.ConstraintSecurityHandler.doStart(ConstraintSecurityHandler.java:457)
at org.eclipse.ponent.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
...................
2013-05-21 14:33:31.267:WARN:oejuc.AbstractLifeCycle:main: FAILED org.eclipse.jetty.server.session.SessionHandler@5b5e91e5: java.lang.IllegalStateException: No LoginService for org.eclipse.jetty.security.authentication.FormAuthenticator@790bb6f4 in org.eclipse.jetty.security.ConstraintSecurityHandler@70188b41
java.lang.IllegalStateException: No LoginService for org.eclipse.jetty.security.authentication.FormAuthenticator@790bb6f4 in org.eclipse.jetty.security.ConstraintSecurityHandler@70188b41
at org.eclipse.jetty.security.authentication.LoginAuthenticator.setConfiguration(LoginAuthenticator.java:67)
at org.eclipse.jetty.security.authentication.FormAuthenticator.setConfiguration(FormAuthenticator.java:131)
...................
2013-05-21 14:33:31.268:WARN:oejw.WebAppContext:main: Failed startup of context o.e.j.w.WebAppContext@729b9707{/jenkins,file:/tmp/jetty-0.0.0.0-8080-jenkins.war-_jenkins-any-/webapp/,STARTING}{/root/jetty-9.0.3/webapps.demo/jenkins.war}
java.lang.IllegalStateException: No LoginService for org.eclipse.jetty.security.authentication.FormAuthenticator@790bb6f4 in org.eclipse.jetty.security.ConstraintSecurityHandler@70188b41
at org.eclipse.jetty.security.authentication.LoginAuthenticator.setConfiguration(LoginAuthenticator.java:67)
at org.eclipse.jetty.security.authentication.FormAuthenticator.setConfiguration(FormAuthenticator.java:131)
at org.eclipse.jetty.security.SecurityHandler.doStart(SecurityHandler.java:375)
at org.eclipse.jetty.security.ConstraintSecurityHandler.doStart(ConstraintSecurityHandler.java:457)
at org.eclipse.ponent.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
at org.eclipse.ponent.ContainerLifeCycle.start(ContainerLifeCycle.java:108)
at org.eclipse.ponent.ContainerLifeCycle.doStart(ContainerLifeCycle.java:90)
原因:Jetty 8.1.0之后对安全性有了一些要求,需要显示注明安全域(security realm)。
解决方法:编辑(或新建) webapps/jenkins.xml 文件,添加如下配置。
&Configure class=&org.eclipse.jetty.webapp.WebAppContext&&
&Set name=&contextPath&&/jenkins&/Set&
&Set name=&war&&&SystemProperty name=&jetty.home& default=&.&/&/webapps/jenkins.war&/Set&
&Get name=&securityHandler&&
&Set name=&loginService&&
&New class=&org.eclipse.jetty.security.HashLoginService&&
&Set name=&name&&Jenkins Realm&/Set&
&Set name=&config&&&SystemProperty name=&jetty.home& default=&.&/&/etc/realm.properties&/Set&
&/Configure&
另外,Jetty 自带的示例:webapps.demo/test.xml 中也有security realm相关的配置。
解决了这两个问题后,Jenkins示例URL:http://192.168.52.11:8080/jenkins/ 就可以正常访问了。
参考资料:
http://www.eclipse.org/jetty/documentation/current/what-jetty-version.html
/questions/9111759/http-error-503-accessing-jenkins-reason-service-unavailable
https://wiki.jenkins-ci.org/display/JENKINS/Jetty
已发表评论数()
请填写推刊名
描述不能大于100个字符!
权限设置: 公开
仅自己可见
正文不准确
标题不准确
排版有问题
主题不准确
没有分页内容
图片无法显示
视频无法显示
与原文不一致Jenkins+Ant自动构建war包并部署远程tomcat下
这里用eclipse为例,进行打包上传。
①.新建Java项目,并引入相关jar包
注:右图,由于我的项目里用了testng,所以引入testng的jar。
②.新建Ant的build.xml文件,并编写打包步骤
&右键,Export-Ant
Buildfiles;删除build.xml中的内容,编辑需要做的步骤,如下:
③.新建folder,加入所需jar包
④.运行build.xml,验证是否能在本地正常打包
右键build.xml,Run As-Ant
Build,结果如下,可见构建成功,到本地相应目录查看成功打包的war包:
⑤.将代码上传svn
右键项目,Team-Share Project-SVN,输入上传地址,finish即可。
⑥.启动Jenkins,并进行配置
注:基础配置见《selenium2.0+testng+ant+Jenkins自动集成环境搭建》
& & ⑥①.安装远端上传插件
& 系统管理-管理插件,搜索中输入‘’并安装;
& & ⑥②.新建项目,并选择【增加构建后操作步骤】如下:
& &⑥③.配置源和目的,并保存
&⑥④.构建,并查看构建日志
&&⑥⑤.查看构建日志是否成功
⑥⑥.查看远程tomcat是否成功部署了此war
可见,Jenkins不仅帮忙上传了war包,还一并给解压缩了,真是一步到位,这时候我们只需要重启服务即可。
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。Deploying jenkins war file using java command - Stack Overflow
to customize your list.
Join the Stack Overflow Community
Stack Overflow is a community of 6.3 million programmers, just like you, helping each other.
J it only takes a minute:
I am trying to deploy a jenkins war file. I executed the following command
java -jar jenkins.war
Below is the log file.
PS C:\Sites> java -jar jenkins.war Running from: C:\Sites\jenkins.war
webroot: $user.home/.jenkins Sep 03, :15 PM winstone.Logger
logInternal INFO: Beginning extraction from war file Sep 03, 2014
6:09:28 PM org.eclipse.jetty.util.log.JavaUtilLog info INFO:
jetty-8.y.z-SNAPSHOT Sep 03, :35 PM
org.eclipse.jetty.util.log.JavaUtilLog info INFO: NO JSP Support for ,
did not find org.apache.jasper.servlet.JspServlet Jenkins home
directory: C:\Users\Mathew.jenkins found at: $user.home/.jenkins
Sep 03, :46 PM org.eclipse.jetty.util.log.JavaUtilLog info
INFO: Started SelectChannelConnector@0.0.0.0:8080 Sep 03, :46
PM winstone.Logger logInternal INFO: Winstone Servlet Engine v2.0
running: controlPort=disabled Sep 03, :46 PM
jenkins.InitReactorRunner$1 onAttained INFO: Started initialization
Sep 03, :26 PM jenkins.InitReactorRunner$1 onAttained INFO:
Listed all plugins Sep 03, :26 PM jenkins.InitReactorRunner$1
onAttained INFO: Prepared all plugins Sep 03, :26 PM
jenkins.InitReactorRunner$1 onAttained INFO: Started all plugins Sep
03, :26 PM jenkins.InitReactorRunner$1 onAttained INFO:
Augmented all extensions Sep 03, :26 PM
jenkins.InitReactorRunner$1 onAttained INFO: Loaded all jobs Sep 03,
:42 PM org.jenkinsci.main.modules.sshd.SSHD start INFO:
Started SSHD at port 55062 Sep 03, :45 PM
jenkins.InitReactorRunner$1 onAttained INFO: Completed initialization
Sep 03, :45 PM hudson.WebAppMain$3 run INFO: Jenkins is fully
up and running Sep 03, :48 PM
hudson.model.DownloadService$Downloadable load INFO: Obtained the
updated data file for hudson.tasks.Maven.MavenInstaller Sep 03, 2014
6:11:51 PM hudson.model.DownloadService$Downloadable load INFO:
Obtained the updated data file for hudson.tasks.Ant.AntInstaller Sep
03, :52 PM hudson.model.DownloadService$Downloadable load
INFO: Obtained the updated data file for hudson.tools.JDKInstaller Sep
03, :11 PM hudson.model.UpdateSite updateData INFO: Obtained
the latest update center data file for UpdateSource default
Can anyone tell me what does the command java-jar jenkins.war do?
WHere did it deploy my war file?
Which web server does it use and how does localhost:8080 point to jenkins application?
Q. Can anyone tell me what does the command java -jar jenkins.war do?
java -jar expects a jar file name, in this case, jenkins.war.
An executable Java program can be packaged in a JAR file, along with any libraries the program uses. Executable JAR files have the manifest specifying the entry point class with Main-Class: myPrograms.MyClass and an explicit Class-Path (and the -cp argument is ignored). Some operating systems can run these directly when clicked. The typical invocation is "java -jar foo.jar" from a command line
Reference:
Q. Where did it deploy my war file?
In case it is a RHEL/CentOS installation, your war is deployed at /var/lib/jenkins
You can find out the location by reading the file /etc/init.d/jenkins. You will find a variable named JENKINS_CONFIG
JENKINS_CONFIG=/etc/sysconfig/jenkins
Q. Which web server does it use and how does localhost:8080 point to jenkins application?
In case it is a RHEL/CentOS installation, you will generally find the file here: /etc/sysconfig/jenkins. In this file, you define port on which Jenkins runs.
2,49421424
1) It executes the java arvhive jenkins.war (see )
2) From the output you posted yourself:
Running from: C:\Sites\jenkins.war webroot: $user.home/.jenkins
the user.home variable may refer to your ~ directory on Linux, or your Document and Settings on windows. See
3) From the output you posted yourself:
jetty-8.y.z-SNAPSHOT
INFO: Started SelectChannelConnector@0.0.0.0:8080
See . This is a web server that register a listener on port 8080.
it uses the Manifest.mf inside, if you open the war, you would understand how it runs
The Main class uses winstone
I would recommend to use glassfish, jetty or tomcat - for better control on configuration
there is a bug open for that
Also see various container notes
1,93911727
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
Upcoming Events
Stack Overflow works best with JavaScript enabled

我要回帖

更多关于 jenkins 打包war 的文章

 

随机推荐