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.
 build.xml
<?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"
classpath="${path.lib}/wlfullclient.jar"/>
<!-- 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"/>
<manifest>
<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"/>
</manifest>
</war>
</target>
<!-- Deploys shared libraries to a WebLogic server -->
<target name="sharedlibs-deploy" depends="sharedlibs-package">
<input message="WLS admin url:" addproperty="wls.adminurl"
defaultvalue="${wls.default.adminurl}"/>
<input message="WLS user:" addproperty="wls.user"
defaultvalue="${wls.default.user}"/>
<input message="WLS password:" addproperty="wls.passwd"
defaultvalue="${wls.default.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"/>
</antcall>
</target>
<!-- Undeploys and then deploys an EAR/WAR file to WebLogic server -->
<target name="wlsdeploy">
<wldeploy action="undeploy" failonerror="false"
name="${wlsdeploy.name}"
adminurl="${wls.adminurl}" targets="${wls.targets}"
user="${wls.user}" password="${wls.passwd}"
/>
<wldeploy action="deploy" library="${wlsdeploy.library}"
upload="true" remote="true" verbose="true"
name="${wlsdeploy.name}"
source="${wlsdeploy.path}"
adminurl="${wls.adminurl}" targets="${wls.targets}"
user="${wls.user}" password="${wls.passwd}"
/>
</target>
</project>




-i

Hope you found this post useful...

...so please read on! I love writing articles that provide beneficial information, tips and examples to my readers. All information on my blog is provided free of charge and I encourage you to share it as you wish. There is a small favour I ask in return however - engage in comments below, provide feedback, and if you see mistakes let me know.

If you want to show additional support and help me pay for web hosting and domain name registration, donations, no matter how small, are always welcome!

Use of any information contained in this blog post/article is subject to this disclaimer.
comments powered by Disqus
Other posts you may like...