在利用Jenkins实现Weblogic应用自动部署的功能时,如何通过Shell 脚本自动更新Weblogic部署的应用程序呢?

可以使用weblogic.jar包中的weblogic.Deployer这个class 。

命令如下:

java weblogic.Deployer -adminurl t3://192.168.142.136:47001 -user weblogic -password weblogic123  -name session -targets sysmanm  -redeploy

其中t3://192.168.142.136:7001 是我管理服务(即AdminServer)的的IP地址和端口,weblogic 是我登录weblogic控制台的用户名,weblogic123是密码 , session是部署的应用名称,sysmanm 是托管服务名,我的session应用就部署在这个服务上。

另在使用命令之前,可以shell脚本中加上weblogic的环境变量,否则可能报找不到CLASS的错误。

完成的sysmanm_redeploy.sh脚本如下:

export CLASSPATH=/usr/java/1.8.0_111/lib/tools.jar:/home/hadoop/Oracle/Middleware/Oracle_Home/wlserver/server/lib/weblogic_sp.jar:/home/hadoop/Oracle/Middleware/Oracle_Home/wlserver/server/lib/weblogic.jar:/home/hadoop/Oracle/Middleware/Oracle_Home/wlserver/server/lib/webservices.jar:/home/hadoop/Oracle/Middleware/Oracle_Home/wlserver/../oracle_common/modules/org.apache.ant_1.7.1/lib/ant-all.jar:/home/hadoop/Oracle/Middleware/Oracle_Home/wlserver/../oracle_common/modules/net.sf.antcontrib_1.1.0.0_1-0b2/lib/ant-contrib.jar:/home/hadoop/Oracle/Middleware/Oracle_Home/wlserver/modules/features/oracle.wls.common.nodemanager_1.0.0.0.jar:.:/usr/java/1.8.0_111/lib/dt.jar:/usr/java/1.8.0_111/lib/tools.jar
#java weblogic.WLST testWeblogicStart.py $1 $2 $3 $4 $5
java weblogic.Deployer -adminurl t3://192.168.142.136:7001 -user weblogic -password weblogic123  -name session -targets sysmanm  -redeploy

使用sh sysmanm_redeploy.sh执行脚本

[hadoop@localhost shell]$ sh sysmanm_redeploy.sh
weblogic.Deployer invoked with options:  -adminurl t3://192.168.142.136:7001 -user weblogic -name session -targets sysmanm -redeploy
<Nov 24, 2016 11:50:31 AM CST> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating redeploy operation for application, session [archive: null], to sysmanm .>
Task 4 initiated: [Deployer:149026]redeploy application session on sysmanm.
Task 4 completed: [Deployer:149026]redeploy application session on sysmanm.
Target state: redeploy completed on Server sysmanm

如下是我本地weblogic服务的简单配置,大家可以参考:

技术图片

 

 

技术图片

 

 技术图片

 

 

附上weblogic.Deployer的帮助信息,如下:

Usage: java weblogic.Deployer [options] [action] [Deployment units(s)]
where options include:
-help Print the standard usage message.
-version Print version information.
-adminurl <<protocol>://<server>:<port>> [option] Administration
server URL: default t3://localhost:7001
-username <username> [option] user name
-password <password> [option] password for the user
-userconfigfile <userconfigfile> [option] The user config file
contains the user security credentials; it
is administered by the weblogic.Admin tool
-userkeyfile <keyConfigFile> [option] The users key file; it is
administered by the weblogic.Admin tool.
-distribute [action] Distribute application to the
targets.
-start [action] Makes an already distributed
application available on a target.
-stop [action] Makes an application unavailable on
targets.
-redeploy [action] Replace a running application
partially or entirely.
-undeploy [action] Take an application out of service.
-deploy [action] Make an application available for
service.
-update [action] Update an application configuration
in place.
-examples [option] Displays example usage of this tool.
-name <application name> [option] Defaults to the basename of the
deployment file or directory.
-targets <<target(s)>> [option] A comma separated list of targets
for the current operation. If not specified,
all configured targets are used. For a new
application, the default target is the
administration server.
-plan <Deployment plan path> [option] Specifies location of
deployment plan
-library [option] Indicates that the unit being
deployed is a library. This option is
required when the application is a library.
-advanced Print advanced usage options.
 
The optional trailing arguments are deployment units and may
represent the archive being deployed, the name of a previously
deployed application or a list of files for a partial redeploy operation.

更多信息请参考:http://docs.oracle.com/middleware/1213/wls/wls-developdeploy.htm