Monday Mar 04, 2013

Integrating JDeveloper into build systems with OJServer

OJServer is a headless instance of JDeveloper.

You might ask what good is an IDE without a UI. Well if you think about it, an IDE is a collection of tools within a UI, but sometimes you want to use a tool without spending too much time interacting with its UI elements. Or you may want to use the same tool on multiple projects or files which would be cumbersome to open and close within an IDE.

Typically, most tools used within an IDE (like the java compiler) can also be run outside of it independently, but you may already have configured your IDE environment in a certain way so that the compiler is launched with the correct options, and your preferences and settings may be configured to your liking. Although these can be duplicated or copied or even referenced in some cases, its not quite the same context. Some tools, like the Refactoring tool, may not have a command-line equivalent, but you may still want to use some of these tools in your headless build environment.

OJServer can help integrate the capabilities of JDeveloper with other build systems. OJServer starts JDeveloper in headless mode and also starts up an RMI listener that listens for service requests. Each service is a distinct unit of work that can be triggered by a remote client. The service gets a JDeveloper context and can execute any arbitrary API available within the IDE (excluding View APIs of course).

By default, OJServer comes with two services pre-defined, a simple "Ping" service and a "Deploy" service. Here's how the Ping service is written:

Ping Service

package oracle.example.ojserver;

import oracle.jdeveloper.ojserver.spi.Server;
import oracle.jdeveloper.ojserver.spi.Service;
import oracle.jdeveloper.ojserver.spi.ServiceContext;

public class PingService implements Service {


    @Override
    public void start(Server server) {
        // Setup code goes here...
        
        server.getLogger().info("Ping service started");
    }

    @Override
    public void execute(ServiceContext serviceContext) {
        
        String greeting = (String) serviceContext.getProperty("greeting");
        serviceContext.getServer().getLogger().info("Server pinged! Text is " + serviceContext.getProperty("greeting"));
        serviceContext.setResult(new Date());
    }

    @Override
    public void stop(Server server) {
        // Release resources..
        
        server.getLogger().info("Ping service stopped");
    }
}
Create a JDeveloper extension with this service and plug it in using a trigger hook.

Registering the Service

META-INF/extension.xml


 <ojserver-hook xmlns="http://xmlns.oracle.com/ide/extension">
   <service name="ping"
            class="oracle.jdevimpl.ojserver.PingService"/>
 </ojserver-hook>

</triggers>

The Ping client

package oracle.example.client;

import java.net.MalformedURLException;

import java.rmi.NotBoundException;
import java.rmi.RemoteException;

import oracle.jdeveloper.ojserver.OjClient;
import oracle.jdeveloper.ojserver.rmi.DefaultClientContext;


public class OJPing {
    public static void main(String[] args) {
        // Accept greeting  from args
        if ( args.length == 0 ) {
            printUsage();
            System.exit(1);
        }
        // Optionally also accept OJServer host and port from args
        // For now, we assume defaults.
        
        
        String greeting = args[0];
        
        
        OjClient client = new OjClient("localhost", 2010);
        DefaultClientContext context = new DefaultClientContext();
        
        context.setProperty("greeting", greeting);


        try {
            client.invoke("PingService", context);
            
            Object result = context.getResult();
            System.out.println("OJServer returned " + result);
            
            System.exit(0);
            
        } catch (NotBoundException e) {
            System.out.println("Invalid service name");
            System.exit(1);
        } catch (MalformedURLException e) {
            System.out.println("Invalid server URL");
            System.exit(1);
        } catch (RemoteException e) {
            System.out.println("Exception on Server: " + e.getMessage());
            System.exit(1);
        }
        
    }

    private static void printUsage() {
        System.out.println("OJPing <greeting> ");
    }
}

Tuesday Feb 26, 2013

Hello World - Code Sample

JDeveloper Project:

DeploymentPlugins.zip

Description

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.

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.


About

Tips and Techniques on extending JDeveloper

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today