Script to deploy application in websphere

ibm websphere

Using wsadmin with individual commands can be difficult when you want to run multiple commands and use variables to store transient data. Also, wsadmin doesn’t have a history of the previous command executed. It is recommended that you run all your scripts via a command file. A command file is just a text-based file containing the Jython commands you wish to execute. A scripted command file contains Jython commands and is passed to wsadmin via the command line.

Listing installed applications with Jython

1. Create a folder called jython in your <scripts_home> folder.

2. Take the following code and paste it into a new file called listApplications.py and save:

#This Jython code will list all the applications installed on your WebSphere server.

print AdminApp.list()

3. Run the script by typing the following command:

°° For Linux:

<was_profile_root>/bin/wsadmin.sh -lang jython -f <scripts_home>/jython/listApplications.py

°° For Windows:

<was_profile_root>\bin\wsadmin.bat -lang jython -f <scripts_home>\jython\listApplications.py

The result of running the script will be a listing of the installed applications on your WebSphere server. you will get the listing shown as follows:

WASX7209I: Connected to process "server01" on node node01 using SOAP connector; The type of process is: UnManagedProcess
DefaultApplication
MYFirstEAR

 

Installing an application using Jython


We will create two Jython script files to be called by the wsadmin tool. One script will install (deploy) an application and the other will uninstall it.

1. Create a file called <scripts_home>/jython/uninstallApp.py

2. Copy in the following code:

#Uninstall the application
deployEAR="<deploy_home>/MYFirstEAR.ear"
appName="MYFirstEAR"
AdminApp.uninstall(appName);
#save
AdminConfig.save();

3. Save the uninstallApp.py file.

4. To run the installation, type the following command:

°° For Linux:
<was_profile_root>/bin/wsadmin.sh –username wasadmin –password wasadmin -lang jython -f <scripts_home>/jython/uninstallHR.py
°° For Windows:
<was_profile_root>\bin\wsadmin.bat –username wasadmin –password wasadmin -lang jython -f <scripts_home>\jython\uninstallHR.py

5. The result of the preceding script will be similar to the following:

WASX7209I: Connected to process "server01" on node node01 using SOAP connector; The type of process is: UnManagedProcess
ADMA5017I: Uninstallation of MYFirstEAR started.
ADMA5104I: The server index entry for WebSphere:cell=s15418557Node01Cell,node=node01 is updated successfully.
ADMA5102I: The configuration data for MYFirstEAR from the configuration repository is deleted successfully.
ADMA5011I: The cleanup of the temp directory for application MYFirstEAR is complete.
ADMA5106I: Application MYFirstEAR uninstalled successfully.

We have now uninstalled the HRLister EAR file. We want to reinstall it using a different script containing Jython to install an application.

6. Create a file called <scripts_home>/jython/installApp.py.

7. Copy in the following code:

#install the application
deployEAR="<scripts_home/deploy>/MYFirstEAR.ear"
appName="MYFirstEAR"
attr="-appname " + appName + " "
AdminApp.install(deployEAR, "["+attr+"]" );
#save
AdminConfig.save();

8. Save the installApp.py file.

9. To run the installation, type the following command:

°° For Linux:
<was_profile_root>/bin/wsadmin.sh –username wasadmin –password wasadmin -lang jython -f <scripts_home>/jython/installHR.py
°° For Windows:
<was_profile_root>\bin\wsadmin.bat–username wasadmin –password wasadmin -lang jython -f <scripts_home>\installHR.py

10. The result will be similar to the following screen output:

WASX7209I: Connected to process "server01" on node node01 using SOAP connector; The type of process is: UnManagedProcess
ADMA5016I: Installation of MYFirstEAR started.
ADMA5058I: Application and module versions are validated with versions of deployment targets.
ADMA5005I: The application MYFirstEAR is configured in the WebSphere Application Server repository.
ADMA5053I: The library references for the installed optional package are created.
ADMA5005I: The application MYFirstEAR is configured in the WebSphere Application Server repository.
ADMA5001I: The application binaries are saved in /var/apps/was8/profiles/appsrv01/wstemp/Script12ee94c8510/workspace/cells/s15418557Node01Cell/applications/MYFirstEAR.ear/MYFirstEAR.ear
ADMA5005I: The application MYFirstEAR is configured in the WebSphere Application Server repository.
SECJ0400I: Successfully updated the application MYFirstEAR with the appContextIDForSecurity information.
ADMA5005I: The application MYFirstEAR is configured in the WebSphere Application Server repository.
ADMA5113I: Activation plan created successfully.
ADMA5011I: The cleanup of the temp directory for application MYFirstEAR is complete.
ADMA5013I: Application MYFirstEAR installed successfully.

 

In case of any ©Copyright or missing credits issue please check CopyRights page for faster resolutions.

Leave a Reply