Tuesday Feb 26, 2013

Hello World - Code Sample

JDeveloper Project:



Complete JDeveloper Application with two Projects showing how to write a Deployment Extension and plug it into the IDE. The first extension adds the deployment code, the second extension surfaces a menu item labelled "Say Hello World" under the "Run" menu. For explanations see this blog entry.

Before running the project, go to Project Properties/Extension and select your target platform.

To run, right-click and select "Run Extension", or you can also "Deploy to Target Platform" and run the IDE manually.

Monday Feb 25, 2013

Hello World

JDeveloper's deployment framework predates Ant, Maven and other such build and project management tools, but you'll find similarities in the concept even if there are differences in terminology and implementation. For one, to change anything in deployment a JDeveloper Extension has to be plugged in. You can find many examples on how to write a JDeveloper Extension in the Extension SDK docs (ESDK) available with JDeveloper. The examples here will work with JDeveloper 11.1.2.x.

The deployment process is a series of steps, each step uniquely identified by a "Sequence". Sequences are analogous to targets in Ant. A sequence may consist of other child sequences that all have to be processed, just like a target can decompose into other targets. The actual processing or step is done by a "Deployer" that is tied to that sequence.

 Lets write the canonical "Hello World" example using the deployment APIs. The deployment sequence for this example will just print the greeting and exit.

Create the following classes:

1. A simple Element: Typically JDeveloper deployment operates on a target, like an Application or Workspace, a Project, or a Deployment Profile within an IDE Context, but for this short example since we do not have a valid target, we'll just make one up and stick it in empty context.

2. A Deployer: To print the message

3. A DeployerFactory: To plug in the Deployer at the correct point.


import oracle.ide.model.DefaultElement; 
public class MyElement extends DefaultElement {} 



import oracle.jdeveloper.deploy.DeploymentManager;

public interface MySequences {
  final static int GREETING_SEQUENCE = 


import oracle.jdeveloper.deploy.DeployShell; import oracle.jdeveloper.deploy.common.AbstractDeployer; public class GreetingDeployer extends AbstractDeployer { public GreetingDeployer(int currentSequence) { super( currentSequence ); } @Override protected void deployImpl(int i, DeployShell deployShell) { deployShell.getLogger().info("Hello World!"); } }


import oracle.jdeveloper.deploy.DeployShell;
import oracle.jdeveloper.deploy.Deployer;
import oracle.jdeveloper.deploy.DeployerFactory;

import oracle.deploy.example.MySequences;

public class MyDeployerFactory implements DeployerFactory {

    public Deployer newDeployer(int sequence, DeployShell deployShell) {
        if ( sequence == MySequences.GREETING_SEQUENCE ) {
            return new GreetingDeployer(sequence);
        return null;

Register the DeployerFactory using "trigger-hooks" in the Extension Manifest ( extension.xml )

<trigger-hooks xmlns="http://xmlns.oracle.com/ide/extension"> <triggers> <deployment-hook xmlns="http://xmlns.oracle.com/jdeveloper/1013/jdev-deployment"> <deployer-factories> <deployer-factory> <deployable-class>oracle.deploy.example.MyElement</deployable-class> <factory-class>oracle.deploy.example.MyDeployerFactory</factory-class> </deployer-factory> </deployer-factories> </deployment-hook> </triggers> </trigger-hooks> 

Build and install the Extension and find a way to trigger the deployment. Usually this is via a menu or an IDE action. To run the deployment, get an instance of DeploymentManager and call it with the new sequence and an IDE Context. The following example shows this being triggered from a (menu) Controller

import oracle.deploy.example.MyElement;
import oracle.deploy.example.MySequences;

import oracle.ide.Context;
import oracle.ide.controller.Controller;
import oracle.ide.controller.IdeAction;
import oracle.ide.dialogs.ExceptionDialog;

public class MyController implements Controller { @Override public boolean handleEvent(IdeAction ideAction, Context context) { context.setElement(new MyElement()); try { DeploymentManager.deploy(MySequences.GREETING_SEQUENCE, context); } catch (Exception e) { ExceptionDialog.showExceptionDialog(context, e); } return true; } @Override public boolean update(IdeAction ideAction, Context context) { return true; } } 

Trigger the controller and you should be rewarded with these messages in your Log window.
Feb 25, 2013 12:35:09 PM oracle.jdevimpl.deploy.fwk.TopLevelDeployer prepareImpl
INFO: ----  Deployment started.  ----
Feb 25, 2013 12:35:09 PM oracle.jdevimpl.deploy.fwk.TopLevelDeployer printTargetPlatform
INFO: Target platform is Standard Java EE.
Feb 25, 2013 12:35:09 PM oracle.deploy.example.GreetingDeployer deployImpl
INFO: Hello World!
Feb 25, 2013 12:35:09 PM oracle.jdevimpl.deploy.fwk.TopLevelDeployer finishImpl
INFO: Elapsed time for deployment:  less than one second
Feb 25, 2013 12:35:09 PM oracle.jdevimpl.deploy.fwk.TopLevelDeployer finishImpl
INFO: ----  Deployment finished.  ----

Tip: Its a good practice to separate the View/Controller classes into a different extension from the deployer code which should have no GUI dependencies. As we'll see later this helps when running deployment from the command-line using ojdeploy. The JDeveloper Deployment API extensions (which are OSGi bundles) follow this convention, for example, there is the "deploy.core" bundle that is required for the above example, and "deploy.core.dt" bundle that is only required for accessing parts of the deployment UI within the IDE.

Thursday Feb 21, 2013

Deploying applications from JDeveloper

Oracle JDeveloper offers a one-stop deployment feature that lets you package your Application or Projects in various kinds of modules and deploy locally or to a remote server.

The deployment in JDeveloper is geared towards a development experience and not intended to be used to directly deploy to a production environment, although it is possible to do so. In this blog I will attempt to describe various aspects of the deployment feature and offer insights into how it can be customized to suit various requirements. Customization may be done via the UI by simply setting various options or may be involved through programmatic manipulations done by JDeveloper extensions.


Tips and Techniques on extending JDeveloper


February 2013 »