31 March 2011

Running ojdeploy from Ant


JDeveloper deployment is built around deployment profiles. A common implementation is an ArchiveProfile that describes the structure of a JAR archive. Deployment profiles can be created as part of a project or workspace. A command-line tool, ojdeploy, is available to allow deployment of ArchiveProfile(s) without invoking the JDeveloper IDE (JDeveloper does not need to run but it needs to be installed in order to run ojdeploy).

Command line deployment requires a JDeveloper installation, but this installation is invoked in 'headless mode' (this means that JDeveloper does not need to run), not displaying the JDeveloper IDE, loading all extensions defined for headless mode. This form of deployment can read JDeveloper applications and projects and their meta-data. Ant scripts to invoke command line deployment need to be created manually. The resulting deployed archive depends on version of JDeveloper used, and which extensions are enabled when command line deployment is invoked.

Export an Ant Build Script That Uses OJDEPLOY From JDeveloper
To make it easier to create an Ant build script for command line deployment, an Ant script can be generated from JDeveloper.

The Ant script will have the following structure:
The build.xml File






The build.properties generated along with build.xml, will define the additional variables needed for command line deployment:
The build.properties File

   #Thu Mar 31 12:42:42 EEST 2011
oracle.jdeveloper.ant.library=C\:\\Oracle\\Middleware\\jdeveloper\\jdev\\/lib/ant-jdeveloper.jar
output.dir=classes
oracle.home=../../../../../Oracle/Middleware/jdeveloper/
javac.deprecation=off
oracle.jdeveloper.workspace.path=C\:\\JDeveloper\\mywork\\tmp\\DependentLOVtest\\DependentLOVtest.jws
oracle.jdeveloper.deploy.profile.name=*
javac.debug=on
oracle.jdeveloper.deploy.dir=C\:\\JDeveloper\\mywork\\tmp\\DependentLOVtest\\ViewController\\deploy
oracle.jdeveloper.ojdeploy.path=C\:\\Oracle\\Middleware\\jdeveloper\\jdev\\bin\\ojdeploy.exe
javac.nowarn=off
oracle.jdeveloper.project.name=ViewController
oracle.jdeveloper.deploy.outputfile=C\:\\JDeveloper\\mywork\\tmp\\DependentLOVtest\\ViewController\\deploy

                                                    \\${profile.name}


The Ant build script can be run outside of JDeveloper by simply changing to the directory containing build.xml and running Ant. It can also be run from within JDeveloper, by right-clicking on the build.xml node in the Application Navigator and selecting the "all" or the "deploy" targets.

(the build file is rendered when running build file but in this post is ommitted)

Buildfile: C:\JDeveloper\mywork\tmp\DependentLOVtest\ViewController\build.xml

init:

deploy:
[ora:ojdeploy] ----build file----
[ora:ojdeploy]
[ora:ojdeploy]
[ora:ojdeploy]  
[ora:ojdeploy]    
[ora:ojdeploy]    
[ora:ojdeploy]    
[ora:ojdeploy]    
[ora:ojdeploy]    
[ora:ojdeploy]  

[ora:ojdeploy]  
[ora:ojdeploy]    
[ora:ojdeploy]    
[ora:ojdeploy]  

[ora:ojdeploy]

[ora:ojdeploy] ------------------
[ora:ojdeploy] Mar 31, 2011 12:57:42 PM oracle.bali.xml.gui.jdev.JDevXmlContext _setProjectAndAttachDetach
[ora:ojdeploy] INFO: Defensive open of project ViewController.jpr during creation of XmlContext (web.xml)
[ora:ojdeploy] Mar 31, 2011 12:57:43 PM oracle.jdevimpl.deploy.fwk.DeploymentManagerImpl$DeployConsoleLogger willPrepare
[ora:ojdeploy] INFO: ----  Deployment started.  ----
[ora:ojdeploy]
[ora:ojdeploy] Mar 31, 2011 12:57:43 PM oracle.jdevimpl.deploy.fwk.DeploymentManagerImpl$DeployConsoleLogger printTargetPlatform
[ora:ojdeploy] INFO: Target platform is  (Weblogic 10.3).
[ora:ojdeploy]
[ora:ojdeploy] Mar 31, 2011 12:57:43 PM oracle.jdevimpl.deploy.common.ProfileDependencyAnalyzer deployImpl
[ora:ojdeploy] INFO: Running dependency analysis...
[ora:ojdeploy]
[ora:ojdeploy] Mar 31, 2011 12:57:43 PM oracle.jdevimpl.deploy.common.ModulePackagerImpl deployProfiles
[ora:ojdeploy] INFO: Deploying profile...
[ora:ojdeploy]
[ora:ojdeploy] Mar 31, 2011 12:57:46 PM oracle.jdevimpl.deploy.war.WarDeployer writeWarFile
[ora:ojdeploy] INFO: Wrote Web Application Module to file:/C:/JDeveloper/mywork/tmp/DependentLOVtest/ViewController/deploy/DependentLOVtest_ViewController_webapp1.war
[ora:ojdeploy] Mar 31, 2011 12:57:47 PM oracle.jdevimpl.deploy.fwk.DeploymentManagerImpl$DeployConsoleLogger finished
[ora:ojdeploy] INFO: Elapsed time for deployment:  4 seconds
[ora:ojdeploy]
[ora:ojdeploy] Mar 31, 2011 12:57:47 PM oracle.jdevimpl.deploy.fwk.DeploymentManagerImpl$DeployConsoleLogger finished
[ora:ojdeploy] INFO: ----  Deployment finished.  ----
[ora:ojdeploy]
[ora:ojdeploy] Status summary written to /C:/JDeveloper/mywork/tmp/DependentLOVtest/ViewController/deploy/ojdeploy-statuslog.xml

all:

BUILD SUCCESSFUL
Total time: 11 seconds



Notes: By default, the command line deployment task has the nocompile option enabled as the task has dependency on the compile task. If this dependency is removed then the nocompile option can be removed.

It is a best practice to generate an .ear file from JDeveloper for the application. The .ear file will be generated with all the right class dependencies required to deploy it. Deploying with Ant by referring to an application directly without generating an .ear file may require that dependencies for the classes and jars files must be resolved manually.

 Create an ant build file automatically with JDeveloper

 
Use a New Gallery dialog to create a new Ant buildfile for a Java project.
To create a new Ant buildfile and add it to the selected project:

  • In the navigator, select the project to which you want to add an Ant buildfile. 
  • Choose FileNew to open the New Gallery.In the Categories list, expand General and select Ant. In the Items list, double-click Empty Buildfile. 
  • The Create Ant Buildfile dialog opens. For more information at any time, press F1 or click Help. If you wish, enter other directory and file names for the build file.Click OK.
If you are going to use ojdeploy,  do not forget to tick the "Include Packaging Tasks"




2 files will be created under resources (see begining of the post for more).
  • build.xml
  • build.properties
The new build file is added to your project and opened for editing

Notes
Check also OJDeploy revisited libraries not included in compile via ant

Dig more: 
  • JDeveloper's Help

No comments:

Post a Comment

You might also like:

Related Posts Plugin for WordPress, Blogger...
There was an error in this gadget