25 November 2014

PL/SQL Webservice deployment with Apache Ant on Weblogic

I created a PL/SQL Webservice using Oracle JDeveloper. I want to use the same generated source tree for development and testing. 

Deploy/Undeploy/Redeploy
To deploy the webservice to the weblogic applications server I found some Ant deployment examples. 

<target name="deploy">
<wldeploy action="deploy" adminurl="t3://${wls.hostname}:${wls.port}" failonerror="false" name="${deploy.name}" password="${wls.password}" source="${deploy.folder}/${deploy.name}${buildnr}.war" targets="${deploy.target}" user="${wls.username}" verbose="true"/>
</target>
<target name="redeploy">
<wldeploy action="redeploy" adminurl="t3://${wls.hostname}:${wls.port}" failonerror="false" name="${deploy.name}" password="${wls.password}" targets="${deploy.target}" user="${wls.username}" verbose="true"/>
</target>
<target name="undeploy">
<wldeploy action="undeploy" adminurl="t3://${wls.hostname}:${wls.port}" failonerror="false" name="${deploy.name}" password="${wls.password}" targets="${deploy.target}" user="${wls.username}" verbose="true"/>

</target>

I've written some java code to parse the the webservice files to change the datasource inside the javacode. It looks something like "java:comp/env/jdbc/devDS" where devDS is the datasource to the development scheme inside the database. The parser changed it in somehting like "java:comp/env/jdbc/testDS" where testDS is the datasource pointing to the testing environment. The parser also changes entries inside the web.xml so it points to the correct datasource as well. 
It also changes the entry for the webservice-contextpath so I can have the webservice deployed on the same weblogic server. 

After changing the java classes and the xml files I added some entries to the ANT file to make it possible to create a war file.
<target depends="init" name="compile">
<javac debug="true" destdir="classes" executable="${javac.exe}" fork="yes" srcdir="src">
<classpath refid="compile.classpath"/>
<compilerarg value="-Xlint:unchecked"/>
</javac>

</target>
<target depends="compile" name="war">
<war destfile="${deploy.source}" webxml="public_html/WEB-INF/web.xml">
<fileset dir="public_html"/>
<classes dir="classes/"/>
</war>
</target>
I also added a executable and a fork to the javac tag so I can run this from another ANT build file.

I created a default target which does a undeploy, compile, war and then deploy the war to the application server.
<target depends="undeploy,compile,war,deploy" name="all"/>