Thursday, 8 November 2007

Using Oracle Ant Tasks within JDeveloper 10g

With OAS 10.1.3.x they released a set of Ant tasks that enable operations such as application deployment, resource configuration and server lifecycle tasks to be performed. I normally run these from the command line but recently needed to set this up in JDeveloper, his how I did that.

1. Firstly I decided to use this 10.1.3.x how to on the OTN web site
How-To Swap XML Parsers ( zip ) Aug-2006

I downloaded the ZIP file onto my file system so I could set this up in Jdeveloper. The 3 files I need are as follows.

  • ant-oracle.xml
  • build.xml
2. In JDeveloper create a new empty project within a workspace
3. From the Object gallery add a new empty build.xml file
4. Copy the 3 files above into the same directory the build.xml was added to in JDeveloper. Basically you are replacing the empty build.xml and adding the 2 other files needed for oracle ant tasks.
5. Use the Refresh icon on the application navigator to ensure all 3 files appear in the project as shown below.

6. Now we need to configure the file to specify our deployment server settings. I am deploying to a OAS instance named pas_oc4j. That said his the settings I am using , thats pretty much all you need to set in that file.

7. Now we have an empty project , but in order to use this otn how to we need to add a JSP to the project, a library and a few deployment descriptor XML files.
8. Add the library "Oracle XML Parser v2" to the project using the Project Properties dialog
9. Add a new JSP file called "index.jsp" using the new object gallery, I placed it in a folder named "web".

What you will find is a web.xml is created automatically for you once the JSP was created in the public_html\WEB-INF directory. All we need to do now is copy the files below from the downloaded how to ZIP into that directory on the file system and press Refresh to show the files in the JDeveloper project
  • orion-application.xml
  • application.xml
10. Now we are ready to deploy using ant BUT before we do that we need to alter the build.xml as the file downloaded from OTN is setup based on the ZIP file, but in JDeveloper we have a slightly different directory structure so in the build.xml we need to alter the "init" target so it looks as follows which matches our directory structure in the project

<target name="init" depends="common">

<echo message="-----> Initializing project properties"/>

<property name="" value="how-to-swapxmlparser"/>

<property name="" value="${}"/>

<property name="" value="${}-web"/>

<property name="src.dir" value="./public_html"/>

<property name="bld.dir" value="./build"/>

<property name="lib.dir" value="D:\jdev\jdevprod\10132\jdev\mywork\OracleAntDemo\OC4JAntDelpoy/lib"/>

<property name="etc.dir" value="./public_html/WEB-INF"/>

<property name="log.dir" value="./log"/>

<property name="src.web.dir" value="${src.dir}/web"/>

<property name="bld.web.dir" value="${bld.dir}/${}"/>

<property name="bld.ear.dir" value="${bld.dir}/${}"/>

<property name="bld.compiler" value="classic"/>

<property name="class.files" value="**/*.class"/>

<property name="bak.files" value="**/*~"/>


11. You will see I hard coded the full path to the final EAR file we will deploy due to an issue with JDeveloper which once I sort it out I will update this blog with a more elegant way of referring to that file. For now simple replace the full path with your directory structure ensuring "lib" remains as ant script is using the "lib" directory.


12. Right click on build.xml and select -> Run Ant and select the target all

Output as follows

Buildfile: D:\jdev\jdevprod\10132\jdev\mywork\OracleAntDemo\OC4JAntDelpoy\build.xml

[echo] BuildName: how-to-swapxmlparser
[echo] BuildHome: D:\jdev\jdevprod\10132\jdev\mywork\OracleAntDemo\OC4JAntDelpoy
[echo] BuildFile: D:\jdev\jdevprod\10132\jdev\mywork\OracleAntDemo\OC4JAntDelpoy\build.xml
[echo] BuildJVM: 1.5

[echo] -----> Initializing project properties

[echo] -----> Creating the required sub-directories



[echo] ------> Checking to see if OC4J is available to deploy to
[echo] Pinging
[echo] If OC4J is not started, please start it now.


[echo] -----> Deploying the application module deployment (ear) file
[echo] Target: deployer:oc4j:opmn://
[echo] lib.dir: D:\jdev\jdevprod\10132\jdev\mywork\OracleAntDemo\OC4JAntDelpoy/lib/how-to-swapxmlparser.ear
[oracle:deploy] Deploying application how-to-swapxmlparser.
[oracle:deploy] Application deployer for how-to-swapxmlparser COMPLETES.

[echo] -----> Deployed the application components required by OC4J for the execution of this application

[echo] -----> Created all deployable units for the application

Total time: 4 seconds

So after a little tweaking we can easily get the OC4J OTN 10.1.3.x how-to's incorporated into JDeveloper using Oracle Ant Tasks to do our compilation/deployment for us.


Raj said...

I really liked your example. I am in process of automating EAR deployment from CVS to clustered 10gAS ( When I specify the deployer uri in the ant properties file, it doesnot take it and gives me error that "Failed to get Deployment Manager". I am confident that the deployer URI is correct as we use the same in our current shell scripts. I have crosschecked the 10gAS documentation too, and I could not find any mistake in it. Can you please tell me, is there some specific issue with deployer uri when you specify the same in ant properties file or do I need to specify the same in a different way.

Pas Apicella said...

I would probbaly log a support ticket with a simple test case and see why jdev is complaining (if jdev is the reason for it), given as you said the URI looks correct and works outside of jdev, then most likely it's not a URI issue.