Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

NOTE: This article is 3 years or older so its information may no longer be relevant. Read on at your own discretion! Comments for this article have automatically been locked, refer to the FAQ for more details.
Here's a handy ant build file for packaging a shared library for a WebLogic deployment and then deploying this shared library to the WebLogic server.

This build file uses the wldeploy task to do the deployment to WebLogic, this is added from the wlfullclient.jar file which is assumed to be stored in the lib directory.

The shared library information is as follows:
  • Name: com.example.mysharedlib
  • Jar files: commonjar1.jar, commonjar2.jar
  • Version 1.0 (both specification and implementation)
  • Shared library package: my_shared_lib.war

The build file assumes that there is a lib and dist directory already created in the same location as the build file. The lib directory is expected to have the wlfullclient.jar as well as the actual jar files that will be packaged into the shared library WAR file. The WAR file will be placed into the dist directory.

The sharedlibs-package target can have multiple war tasks added to it to create multiple shared libraries. The sharedlibs-deploy task can have additional antcalls to the wlsdeploy target added to then deploy these libraries. The wlsdeploy target first undeploys the existing deployment before deploying it again.

A number of other properties are defined in the script that specify the default WebLogic admin server, user and password as well as the target list. The target list in the script includes just the AdminServer, this should be changed to the actual WebLogic server that the shared library is to be deployed into.
<?xml version="1.0" encoding="US-ASCII" ?>
<project xmlns="antlib:org.apache.tools.ant" name="MySharedLibs" default="sharedlibs-deploy">
<!-- Define the location of the required directories -->
<property name="path.lib" value="lib"/>
<property name="path.dist" value="dist"/>
<property name="wls.default.adminurl" value="t3://localhost:7001"/>
<property name="wls.default.user" value="weblogic"/>
<property name="wls.default.passwd" value="YourSecurePassword"/>
<property name="wls.targets" value="AdminServer"/>
<!-- Additional task definitions -->
<taskdef name="wldeploy" classname="weblogic.ant.taskdefs.management.WLDeploy"
<!-- Packages shared libraries into WAR files -->
<target name="sharedlibs-package">
<war destfile="${path.dist}/my_shared_lib.war" needxmlfile="false">
<lib file="${path.lib}/commonjar1.jar"/>
<lib file="${path.lib}/commonjar2.jar"/>
<attribute name="Specification-Title" value="com.example.mysharedlib"/>
<attribute name="Specification-Version" value="1.0"/>
<attribute name="Implementation-Title" value="com.example.mysharedlib"/>
<attribute name="Implementation-Version" value="1.0"/>
<attribute name="Implementation-Vendor" value="Example Vendor"/>
<attribute name="Extension-Name" value="com.example.mysharedlib"/>
<!-- Deploys shared libraries to a WebLogic server -->
<target name="sharedlibs-deploy" depends="sharedlibs-package">
<input message="WLS admin url:" addproperty="wls.adminurl"
<input message="WLS user:" addproperty="wls.user"
<input message="WLS password:" addproperty="wls.passwd"
<antcall target="wlsdeploy">
<param name="wlsdeploy.name" value="com.example.mysharedlib"/>
<param name="wlsdeploy.path" value="${path.dist}/my_shared_lib.war"/>
<param name="wlsdeploy.library" value="true"/>
<!-- Undeploys and then deploys an EAR/WAR file to WebLogic server -->
<target name="wlsdeploy">
<wldeploy action="undeploy" failonerror="false"
adminurl="${wls.adminurl}" targets="${wls.targets}"
user="${wls.user}" password="${wls.passwd}"
<wldeploy action="deploy" library="${wlsdeploy.library}"
upload="true" remote="true" verbose="true"
adminurl="${wls.adminurl}" targets="${wls.targets}"
user="${wls.user}" password="${wls.passwd}"


Skip down to comments...
A quick disclaimer...

Although I put in a great effort into researching all the topics I cover, mistakes can happen. If you spot something out of place, please do let me know.

All content and opinions expressed on this Blog are my own and do not represent the opinions of my employer (Oracle). Use of any information contained in this blog post/article is subject to this disclaimer.
comments powered by Disqus
Other posts you may like...