Use ojdeploy to build ADF EAR file from source code, at command line

(Note: This post does not make use of Apache Ant. More details regarding this are given at the end of the post).

You may have an ADF application's source code on your machine and want to build its EAR file (for deploying else where), without opening the JDeveloper IDE. This may be the requirement if you want to script the build process, and to do this you cannot open the JDeveloper IDE.

This can be easily done, BUT JDeveloper needs to be installed on the machine you want to do this because you need to make use of the ojdeploy command, which is located within the JDeveloper libraries. Using ojdeploy essentially offers the build commands you may be familiar with from the UI level, but without the UI needing to be open. (Usually referred to as running JDeveloper in 'headless' mode).

(Note: It is possible to do this without having to install JDeveloper on the machine you want to build from, BUT you need to ensure that you have ALL the libraries and classes available to make use of ojdeploy. This can end up being a time consuming and complex task because many different libraries and classes at different folder structures are used. You may have to repeat the process at every new JDeveloper release as libraries and file structures may change. It may be worth going down this path if you are performing this task on a production environment and requirements forbid you from installing JDeveloper on the machine. 9 times out of 10, the benefits of installing JDeveloper are far greater than not doing so. But this is an entirely different discussion).

From the command line, the command that performs the EAR build is:

C:\> full_path_to_ojdeploy.exe -workspace full_path_to_project.jws -profile application_profile_name




The application_profile_name is the name given to the Deployment profile of the application that has been set up. This can be obtained from within the JDeveloper IDE. Click on Application, then Application Properties. Then click on the Deployment tab, and use the name under a Deployment Profile. Example shown below:



The below screenshot of the command line shows how I would get the ojdeploy command executed on my machine. Simply replace the paths for own your build:



Press enter and allow the application to build. The output of the EAR should be in its default location: project_path/deploy. (The location can be modified under the Application Properties by double clicking on the EAR Deployment profile and modifying the output directory).

The following shows the message that we are all happy to see when performing build or deploy tasks, Deployment finished. It also shows you the directory where the EAR file has been deployed to:




Now that you have the EAR, you can manually deploy the file through the server Console or EM. Or you can script the process, which takes the EAR file and then deploys to a specified server. This is particularly useful for build automation tasks, and is usually implemented by using Apache Ant.

Apache Ant
The above process is the most simplistic way of building application EAR files from the command line. But you can combine the above process to call it from ANT tasks/targets and combine the build and deploy process. This involves building a build.xml and build.properties file, which is typically done within the JDeveloper IDE on the current project. These files make use of the ojdeploy command we used earlier. The build.properties file will include paths to certain libraries and folders, again, some of these will be the parameters we passed in with the ojdeploy command.

Configuring the build and deploy process with Ant is a separate task and is out of scope from this post. So I may write a post that further extends this topic in future.

2 comments:

  1. Hi Onkar,

    Really Your blog was helpful to me.My requirement is i want to generate .ear for the current project using ant script(build.xml).














    The above script generates .war and .jar.What should be done to make this together to generate .ear?Kindly explain

    ReplyDelete