Date Created: Mon 20-Dec-2010

Get my WebSphere Application Server course here >>

Running wsadmin.bat from Eclipse by calling a .bat file.

I am using Eclipse for my IBM WebSphere development to save myself 1000's in RAD licenses. There is more than one way to do this ie you can run wsadmin.bat directly from Eclipse and pass command line options. The method I have demonstrated is very generic and can be used for other J2EE servers and other external tools.

Lets say you have added a .bat file called deploy.bat containing the following commands.

C:\IBM\WebSphere\AppServer\bin\wsadmin.bat -username wasadmin -password wasadmin -f

I am using WebSphere version 8 in this example:

The reason I use a batch file is that it allows me the ability to define many different types of calls to different Jython scripts as required during my development process. I usually end up with an additional Eclipse project called by build project where I store all my build goodies.

Once I am in the External Tools Configuration section I am able to click the "New" icon and create a run configuration called deploy.bat. I could have called this anything,but I call it deploy.bat so I know it is going to call a bat file called deploy.bat located in my build project.

I have created a separate build project to contain my Ant build files, jython scripts and bat files.

Note: By clicking Browse Workspace you can get environment variables so your batch file is working in the correct working directory. This way I do not have to add full paths to my bat file as it is relative to the project. This means I can copy my Eclipse project and the external configuration will still work, accept any hard coded paths within batch files ie WebSphere runtime folder etc.

As you can see in the image below, by clicking on Browse Workspace I as able to add the path: ${workspace_loc:/BuildWAR/deploy.bat} by selecting the deploy.bat from project list and an Eclipse relative path was returned.

Now by running the deploy.bat file which calls my file I am able to run my build script to build the EAR file and then deploy it to my local WebSphere 8 install.


C:\eclipse3.5_logview\BuildWAR>C:\IBM\WebSphere\AppServer\bin\wsadmin.bat -username wasadmin -password wasadmin -f
WASX7209I: Connected to process "server1" on node T60Windows7PNode01 using SOAP connector; The type of process is: UnManagedProcess
Checking for Application: LogView
Application LogView doesn't exist
Installing application: LogView
ADMA5016I: Installation of LogView started.
ADMA5058I: Application and module versions are validated with versions of deployment targets.
ADMA5005I: The application LogView is configured in the WebSphere Application Server repository.
ADMA5053I: The library references for the installed optional package are created.
ADMA5005I: The application LogView is configured in the WebSphere Application Server repository.
ADMA5001I: The application binaries are saved in C:\IBM\WebSphere\AppServer\profiles\AppSrv01\wstemp\Script12d04c5cb6d\workspace\cells\T60Windows7PNode01Cell\applications\LogView.ear\LogView.ear
ADMA5005I: The application LogView is configured in the WebSphere Application Server repository.
SECJ0400I: Successfully updated the application LogView with the appContextIDForSecurity information.
ADMA5005I: The application LogView is configured in the WebSphere Application Server repository.
ADMA5113I: Activation plan created successfully.
ADMA5011I: The cleanup of the temp directory for application LogView is complete.
ADMA5013I: Application LogView installed successfully.


import sys
# get line separator
import java
lineSeparator = java.lang.System.getProperty('line.separator')

# Logging
def log(text):
print text

# Logging
def logerror(text):
print ""
print "**************************************************************"
raise SystemExit, text

def checkApplication(appName):
# Check if application exist
print ("Checking for Application: " + appName)
apps = AdminApp.list().split(lineSeparator)
###Listing Installed Applications###
if appName in apps:
print ("Application %s already exists! " % (appName))
print ("Application %s doesn't exist " % (appName))
return appExists

def deleteApplication(appName):

###print ("Enter: deleteApplication")###

# Uninstall the application

print("Uninstalling application: " + appName)

exc_info = sys.exc_info()
print ("Error during Application uninstallation:")
Print ("Exit: deleteApplication")

def installApplication(appName, earFile):
print("Installing application: " + appName)
appOptions="-appname " + appName + " " + "-usedefaultbindings" + " "
AdminApp.install(earFile, appOptions)
exc_info = sys.exc_info()
print ("ERROR: Error during Application installation:")
print (exc_info[1])

# set up globals
global AdminConfig
global AdminControl
global AdminApp
global AdminTask

###print "appExists=True"
installApplication(appName, earFile)
#print "appExists=False"
installApplication(appName, earFile)


<?xml version="1.0" encoding="UTF-8"?>
<project name="Log View EAR build script" default="makeear" basedir=".">
<format property="buildtimestamp" pattern="yyyy-MM-dd'T'HH:mm:ss" />

<condition property="isWindows">
<os family="windows" />

<condition property="isMac">
<os family="unix" />

<echo message="==== Eclipse Workspace Properties ====" />
<echo message="${workspace_loc}" />

<property name="root" value=".." />
<echo message="root=${root}" />

<property name="EARBasePath" value="${root}/LogViewEAR" />
<echo message="EARBasePath=${EARBasePath}" />

<property name="WARBasePath" value="${root}/LogViewWAR" />
<echo message="WARBasePath=${WARBasePath}" />

<property name="lib.dir" value="${WARBasePath}/WebContent/WEB-INF/lib" />
<echo message="lib.dir=${lib.dir}" />

<property name="src.dir" value="${WARBasePath}/src" />
<echo message="src.dir=${src.dir}" />

<property name="pages.dir" value="${WARBasePath}/WebContent" />
<echo message="pages.dir=${pages.dir}" />

<echo message="==== Temp Staging Area &amp; Build Properties ====" />

<property name="package.file" value="LogViewWAR.war" />
<property name="temp.dir" value="c:/temp/antbuild/temp" />
<property name="temp.dir.webcontent" value="${temp.dir}/WebContent" />
<property name="temp.dir.web-inf" value="${temp.dir.webcontent}/WEB-INF" />
<property name="temp.dir.lib" value="${temp.dir.web-inf}/lib" />
<property name="temp.dir.classes" value="${temp.dir.web-inf}/classes" />
<property name="temp.dir.meta-inf" value="${temp.dir.webcontent}/META-INF" />

<property name="dest.dir" value="c:/temp/antbuild/dist/" />

<echo message="====" />

<target name="mac" if="isMac">
<property file="" />
<echo message="${}, using ${props.file}" />

<target name="windows" if="isWindows">
<property file="" />
<echo message="${}, using ${props.file}" />

<target name="os" depends="windows,mac">
<path id="classpath">
<fileset dir="lib">
<include name="*.jar" />


<target name="clean" depends="">
<echo>=== CLEAN ===</echo>
<delete dir="${temp.dir}" />
<delete dir="${dest.dir}" />

<target name="prepare" depends="clean">
<echo>=== PREPARE ===</echo>
<mkdir dir="${dest.dir}" />
<mkdir dir="${temp.dir}" />
<mkdir dir="${temp.dir.lib}" />
<mkdir dir="${temp.dir.webcontent}" />
<mkdir dir="${temp.dir.meta-inf}" />
<mkdir dir="${temp.dir.web-inf}" />
<mkdir dir="${temp.dir.classes}" />

<!-- BUILD ALL -->
<target name="all" depends="makeear">
<echo>=== BUILD ALL ===</echo>
<delete dir="${build}" />

<!-- Set up a path id for external JARS reference during compilation of WAR Java files-->
<path id="build.classpath">
<fileset dir="C:/WAS7/AppServer/lib/">
<include name="j2ee.jar" />

<fileset dir="${lib.dir}">
<include name="simple-log.jar" />


<!-- COMPILE -->
<target name="compile" depends="prepare">
<echo>=== COMPILE ===</echo>
<javac debug="on" srcdir="${src.dir}" destdir="${temp.dir.classes}">
<classpath refid="build.classpath" />

<compilerarg value="-Xlint:unchecked" />


<!-- PACKAGE WAR File -->
<target name="makewar" depends="compile">
<echo>=== PACKAGE WAR ===</echo>

<echo>copy the config files</echo>
<copy file="${WARBasePath}/WebContent/META-INF/MANIFEST.MF" tofile="${temp.dir.meta-inf}/MANIFEST.MF" overwrite="true" />
<!--<copy file="${WARBasePath}/WebContent/WEB-INF/web.xml" tofile="${temp.dir.web-inf}/web.xml" overwrite="true" />-->

<echo>copy the JAR files</echo>
<copy todir="${temp.dir.lib}">
<fileset dir="${WARBasePath}/WebContent/WEB-INF/lib">
<include name="**/*.jar" />

<echo>copy the web content</echo>
<copy todir="${temp.dir.webcontent}">
<fileset dir="${WARBasePath}/WebContent/">
<include name="**/*.html" />
<include name="**/*.jsp" />
<include name="**/*.ico" />


<copy todir="${temp.dir.web-inf}">
<fileset dir="${WARBasePath}/WebContent/WEB-INF">
<include name="**/*.xml" />
<include name="**/*.properties" />

<echo>Build the WAR file...with all resources in place, create the war file</echo>

<war destfile="${dest.dir}/${package.file}" webxml="${temp.dir}/WebContent/WEB-INF/web.xml" update="true">

<fileset dir="${temp.dir}/WebContent">
<exclude name="WEB-INF/web.xml" />


<target name="makeear" depends="makewar">
<echo>=== MAKE EAR ===</echo>
<ear earfile="${dest.dir}/LogViewEAR.ear" appxml="${EARBasePath}/EarContent/META-INF/application.xml">
<fileset dir="${dest.dir}">
<include name="*.war" />

<!--<target name="all">
<delete dir="${build}" />


C:\IBM\WebSphere\AppServer\bin\wsadmin.bat -username wasadmin -password wasadmin -f

Get my WebSphere Application Server course here >>

Steve Robinson - IBM Champion 2013

About Me

Steve Robinson has been working in IT for over 20 years and has provided solutions for many large-enterprise corporate companies across the world. Steve specialises in Java and Middleware.

In January 2013, I was awarded the prestigous 'IBM Champion' accolade.

  • Linked In
  • Twitter
  • About Me
  • My Blog
  • Contact Me

Read my books?

IBM WebSphere Application Server 8.0 Administration Guide

IBM WebSphere Application Server 8.0 Administration Guide

WebSphere Application Server 7.0 Administration Guide

WebSphere Application Server 7.0 Administration Guide

WebSphere Categories

Other Categories