Wednesday Jul 31, 2013

Deployment Profiles explained

A Deployment Profile is a data structure in JDeveloper that describes how to put together the contents of a Project or Application for publishing to a remote target. The target can be the file system, an Application Server, a Mobile device, etc. anything that JDeveloper can interface with.

The most common type of Deployment Profile is a JAR Profile, which lets you simply zip up all the contents of the project into a .jar file. A JAR Profile consists of one or more FileGroups, similar to Ant filesets, but at a higher level of abstraction. A FileGroup has Contributors, that act as the source of files, and filter patterns that select from them. Finally it has a target location within the jar where the selected files should end up.

For example, a "Project Source" contributor would provide all source files, a pattern of "Include **" would select all the files and a target of "src" would put all the source files under the "/src/" directory within the .jar archive.

Similarly, a "Project Output" contributor would get all the compiled .class files. Arbitrary directories can also be added as contributors, but this is usually not a good idea, its better to express the dependency to that directory in some other form and have one of the standard or pre-defined contributors bring it in.

So far we've been referring to a specific type of FileGroup called a Packaging file group. Another useful FileGroup which can be included in a JAR Profile is the Library file group. This file group gathers all the Libraries of a project and adds each one as a contributor source. Based on the definition of the library, it also makes some choices as to which ones to omit. For example, libraries that are not marked 'Deployed by Default' are not added. Users have the option to override the default. Just like the Packagingfile group, the Libraryfile group also lets you select the actual files from the library using patterns, by default all files from a certain library are added (in JDeveloper each Library can have several jar files).

All these actions can be done via UI, or using the API. A default "JAR Profile" is an instance of the ArchiveProfile class. A ProfileFactory is provided as a facade to create any type of profile.

import oracle.ide.Context;
import oracle.jdeveloper.deploy.ProfileFactory;
import oracle.jdeveloper.deploy.jar.ArchiveProfile;

ProfileFactory factory = ProfileFactory.getInstance();

// Create a context for the profile.
// Here we have a pre-existing project.
Context context = new Context( project );

// Create a JAR profile with a single packaging file group and a single
// library file group
MyProfile p = factory.create( "name1", ArchiveProfile.class, context);

Next we'll see how to deploy this profile to disk.

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=""> <triggers> <deployment-hook xmlns=""> <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.


Some tips and techniques for working with Oracle and Eclipse tools.


« June 2016