|
InstallEar
This is wsadmin Jython code snippet to install a WAR/EAR file in WebSphere Application Server
wsadmin, installapplication IntroductionThis is wsadmin Jython code snippet to install a WAR/EAR file in WebSphere Application Server. The script takes path to the WAR or EAR file and the context root of the web app as the parameter, installs the application on the server and starts the app. The code was written to install standalone WAR on WebSphere App Server (There is nice big reason why it was not wrapped in an EAR, but that is another story.) The motivation was the way WAS 6.1 installs standalone WARs when done via wsadmin command prompt. wasadmin picks the war file (say, my-war-file.war) and installes it as my-war-file.warBCBGMAX4234. The weird chars at the end changes every time it is deployed, because of which using command prompt was a pain. After installation the snippet matches the installed war with the list of apps installed using file name and then starts the application. Disclaimer: The code was tested while installing WAR file only and NOT with EAR. May need some changes in the way context-root is handled for it to work with EAR. This code was written to be run in development environment and not meant for production usage (although with some exception handling and parametrization it can be). Check this link for information on how to run this script: http://code.google.com/p/codesnippetssite/wiki/BasicWebSphereAdminwsadmin Details# Jython script to install a EAR or WAR in WebSphere Application Server
#
import sys
#Some Global variables
#WebSphere environment related variables
cellName = 'testvmNode01Cell'
nodeName = 'testvmNode01'
serverName = 'server1'
print '\n\n-------------------------------------------------------------------'
print 'This script will install a EAR/WAR on WebSphere Application Server'
print "\nUsing these WebSphere Defaults:"+"\nCell: "+cellName+"\nNode: "+nodeName+"\nServer: "+serverName
print "\nPass the path to the EAR/WAR and web-app's context-root as parameters. File path should be in this format:"
print "\tc:\\\\osgiapps\\\\war-to-install.war (With double back-slashes)"
print "\nPlease edit the variables in the script if these defaults need to be changed."
print '-------------------------------------------------------------------\n\n'
numberOfArgs = len(sys.argv)
if numberOfArgs < 2:
print "Usage: installApp.py {file-absolute-path} {context-root}"
else:
#Get the absolute path of the WAR file and replace \ with /
filePath1 = str(sys.argv[0])
contextRoot = str(sys.argv[1])
filePath1 = filePath1.replace('\\', '/')
#Get the name of the WAR file:
strAppToInstall = filePath1[filePath1.rfind("/")+1:len(filePath1)];
print "Installing ", strAppToInstall, " from ", filePath1;
#Uninstall the app if already deployed.
appToUninstall = ""
appsBefore = AdminApp.list().split("\n");
for iApp in appsBefore:
if str(iApp).find(strAppToInstall) >= 0:
appToUninstall = iApp;
if appToUninstall:
print "Uninstalling app: ", appToUninstall
appToUninstall = str(appToUninstall).strip();
AdminApp.uninstall(appToUninstall)
AdminConfig.save();
#Install the app
print "Installing App: ", strAppToInstall
AdminApp.install(filePath1, "-contextroot /"+contextRoot+" -defaultbinding.virtual.host default_host -usedefaultbindings");
AdminConfig.save();
#Start the app
apps = AdminApp.list().split("\n");
theApp = ""
for iApp in apps:
if str(iApp).find(strAppToInstall) >= 0:
theApp = iApp;
print "Starting App: ", theApp
appManager = AdminControl.queryNames('cell='+cellName+',node='+nodeName+',type=ApplicationManager,process='+serverName+',*')
AdminControl.invoke(appManager, 'startApplication', theApp)
print "Application installed and started successfuly!"
|
Thanks rakzra! The Jython script works fine. After the application startup I am not able to access the application, but once I restart WAS, able to access the app. I have added some additional jars in /opt/IBM/WebSphere?/AppServer?/lib. InstallApp?.py give error message like "sys-package-mgr: can't write cache file" along with "Successfully started" messsage. Will the reason be b'z of cachedir permission? cachedir's owner is root(rwxr-xr-x) but I am running as different user. cachedir's path is /opt/IBM/WebSphere?/Profiles/AppSrv01?/temp/cachedir.
Thank you so much man.You have no idea how helpful this script is.I was fighting for almost a day to get my EAR deployed on WAS untill i found this.Greatly Appreciate!
Hi! I am getting IndexError?: index out of range: 0 when I type str(sys.argv0?). How can I check if filePath1 has the right path?
In addition after I run this same script my application is not yet installed. I also get SyntaxError?: invalid syntax in line theApp = iApp;
I am really interested on how do you get the absolute path of the war file