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.

Update Date value in Database table/VO through a Managed Bean

A lot of time can be spent trying to convert objects to different types to make them compatible to different reference points. I had a problem where I had to update the Date value in a VO through a managed bean and spent a fair amount of time getting the types correct. So here is the code to do so:

//imports for following code
import java.sql.Timestamp;
import java.util.Date;
import oracle.adf.model.AttributeBinding;

//Get current date/time to be used to update VO date value
Date currentDate = new Date();

//Convert date variable to DB Date type
oracle.jbo.domain.Date date = new oracle.jbo.domain.Date(newTimestamp(currentDate.getTime())); 

//Get the attribute that the Date is set to in your page
AttributeBinding dateTimeAttr = AttributeBinding)bindings.getControlBinding("DateTime"); 

//Set the attribute with the newly created date variable
noteCreatedDateAttr.setInputValue(date);

Configure Android SDK with JDeveloper 11.1.2.4.0 for ADF Mobile Application Development

I spent several hours trying to figure out how to deploy an ADF Mobile application to my running desktop Android SDK emulator. I thought it would be worthwhile documenting the process as there are a few tweaks required and I could not find a straight forward guide online. This blog post guides you through the configurations required and assumes that you have a deploy-able ADF Mobile application.

I can provide you with a simple ADF Mobile application if you require it - leave me a comment with your email address.

Installations:
  1. Download Oracle JDeveloper 11.1.2.4.0 (Link)
  2. Download the Android SDK (Link)

AndroidSDK extraction:
  1. Extract the AndroidSDK download to C:/AndroidSDK
  2. Open SDK Manager found in C:/AndroidSDK
  3. Tick Google Cloud Messaging for Android Library, located under the Extras folder (Resolves this bug)

  4. Click Install Package(s), Accept License then click Install


Deployment bug resolution: (Source 1 Source 2)
There is a known bug at the deployment stage that requires the following actions to be performed to resolve:
  1. From C:/AndroidSDK/sdk/build-tools/android-4.2.2, copy the following files and directories:

    - Aapt.exe
     - Dx.bat
    - /libs

  2. Copy the above to C:/AndroidSDK/sdk/platform-tool


Setting up the AndroidSDK emulator with an AVD configuration: (Source)
  1.  Open a Command Prompt and change directory to C:/AndroidSDK/sdk/tools
  2. Enter the following command:
    android list targets

  3.  Record the ID of the Android Platform that you would like to utilise. (Typically, we will only have one and its ID will be 1)
  4.  Enter the following command to create the AVD configuration file: 
    android create avd –n <name> -t <targetID>

    Replace <name> with the name you want for the AVD and <targetID> with the ID recorded from earlier.

    The AVD configuration files will be written to C:/Users/<username>/.android/avd by default.

    To customise the AVD configuration file path, use the following command to create the AVD:

    android create avd –n <name> -t <targetID> -p C:/Path/To/AVD

    5.   The following prompt will appear:
    Do you wish to create a custom hardware profile [no]

    We want to select default, so press Enter.

Running the Android Emulator using an AVD configuration file
  1. Navigate to C:/AndroidSDK/sdk/tools
  2. Use the following command to run an instance of the emulator

    emulator –avd <avd_name>

    Replace <avd_name> with one of the AVD’s you created earlier.
  3. This will boot up the Android Emulator in a new window as shown below:
     Note: Closing the command prompt window that is used to run the emulator will also automatically close the emulator. (I learnt this the hard way!)



Configuring the AndroidSDK within JDeveloper
  1. Open JDeveloper 11.1.2.4.0
  2. Click Tools, then Preferences
  3.  Click ADF Mobile, then Platforms
  4. Select Android under Supported Platforms
  5. Configure the Android SDK Location and Android Platform Location to point to your extracted AndroidSDK location, as shown below:

                    6.  Click OK to finish the configuration.



Create a local key store to use Release Mode (Improved performance)
  1. Open command prompt and change directory to the JDK/bin used by your JDeveloper 11.1.2.4.0

    My path is:
    C:\Middleware2\11_1_2_4_0\jdk160_24\bin
  2. Type the following command into the command prompt (Note: you must type it, not copy):

    keytool –genkey –v –keystore <Keystore Name>.keystore –alias <Alias Name> -keyalg RSA –keysize 2048 –validity 10000

    Replace <Keystore Name> and <Alias Name> with a custom name. I used ‘employees’ for both variables for my setup.

  3. You will be prompted for several values such as a keystore password, your name, city, state etc.
    Enter
    oracle for the keystore password, and enter values for the other prompts. They do not have to be ‘correct’ values.
    Another final password prompt is asked for your <keystore_name> password, enter
    oracle again.
  4. The keystore is ready to use, we now need to configure the connection inside JDeveloper.
  5. Open JDeveloper 11.1.2.4.0. Click Tools, Preferences, ADF Mobile, Platforms and then click on the Release Tab under Signing Credentials.
  6. Enter the required details as shown below. 

Keystore Location: Located under JDK/bin/<Keystore_Name_Chosen>
Keystore Password: oracle
Key Alias: <Alias_Name_Chosen>
Key Password: oracle


         7.   JDeveloper now knows about the keystore, which enables you to select the Release mode in the       deployment profiles


Deploy ADF Mobile App to the Android Emulator 
  1. In JDeveloper, from the Application menu, Select Deploy > New Deployment Profile.
  2. Click Android Options, select Release for the Build Mode, and click OK.
  3. From the Application menu, select Deploy > Above_Deployment_Profile_Name.
  4. Select Deploy application to emulator, click Next, then click Finish.
  5. Wait for Deployment to finish, then switch to the Android Emulator you have running and select your deployment application from the Androids’ apps.