NO.102 Jenkins+Ant实现JDK、WebLogic、Domain批量安装(2)编写JDK8安装脚本

一、概述

本节及下节以编写安装JDK8的ant脚本为例进行描述,并以此掌握两个ant task:scp和sshexec的基本用法。

二、手工安装JDK的前置条件和过程简述

1. 准备好JDK8安装包 ,本地文件位置:d:\tmp\inventory\jdk-8u72-linux-x64.rpm;

2. 准备好一个可在linux服务器可执行安装命名的用户:用户名密码 super/super(为了便于操作,一般将super的用户号改为0);

3. sftp上传jdk-8u72-linux-x64.rpm到服务器,如: /super目录下(super对该目录有执行权限)

4. ssh工具登录linux服务器,执行:

cd /super

rpm -ivh jdk-8u72-linux-x64.rpm

 

 

三、ant脚本编写-学习scp和sshexec的使用

先贴一下全脚本:

 

先是参数文件d:\tmp\build_params.properties:

##########################################
## 参数配置文件                         ##
##########################################

#linux服务器IP
server.ip=10.10.10.10

#安装JDK用的服务器用户名
root.user=super

#密码
root.password=super

#安装包上传到服务器哪个目录下?
upload.path=/super

#本地安装包所在的目录(注意反斜杠是转义符,用斜杠win和linux可通用)
inventory.dir=./inventory

#JDK8 rpm包文件名
JDK8.filename=jdk-8u72-linux-x64.rpm

然后是d:\tmp\build.xml

<?xml version="1.0" ?>
<project>

	<property file="build_params.properties" />

	<!-- rpm方式安装JDK -->	
	<target name="installJDK8ByRpm" >
	  <scp file="${inventory.dir}/${upload.filename}" todir="${root.user}:${root.password}@${server.ip}:${upload.path}/" trust="true"/>
		<sshexec host="${server.ip}" username="${root.user}"  password="${root.password}"
         trust="true" command="cd ${upload.path};rpm -ivh  ${upload.filename}"/>
	</target>
	
</project>

 

新内容主要是scp(文件传输)和sshexec(执行指令)两个Task的使用,具体不多说了。注意,为了方便以后灵活实现各种情况的安装,几乎将所有Task的参数都进行了可配置处理,后续一个脚本中大量使用scp和sshexec时,还会将他们进行封装,以方便调整或优化。

 

 

四、缺包的处理

OK,我们在cmd里运行下

d:

cd \tmp

ant installJDK7ByRpm

结果显示:

BUILD FAILED
D:\tmp\build.xml:14: Problem: failed to create task or type scp
Cause: Could not load a dependent class com/jcraft/jsch/Logger
       It is not enough to have Ant's optional JARs
       you need the JAR files that the optional tasks depend upon.
       Ant's optional task dependencies are listed in the manual.
Action: Determine what extra JAR files are needed, and place them in one of:
        -D:\Program Files\apache-ant-1.9.13\lib
        -D:\Users\Administrator\.ant\lib
        -a directory added on the command line with the -lib argument

Do not panic, this is a common problem.
The commonest cause is a missing JAR.

This is not a bug; it is a configuration problem


Total time: 0 seconds

 

没有执行成功,信息显示“不要方,就是缺个包!

以com/jcraft/jsch/Logger为关键词搜索,我们需要补充一个叫jsch.jar的包,并放入

D:\Program Files\apache-ant-1.9.13\lib目录下。

附jsch-0.1.54.jar的下载地址:

https://sourceforge.net/projects/jsch/files/jsch.jar/0.1.54/jsch-0.1.54.jar/download

 

 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值