Skip to content
sfermigier edited this page May 11, 2011 · 9 revisions

Creating a new Plug-in Project

To create a new ECR plugin, you just need to create an OSGi bundle.

For this, in Eclipse, create a new PDE Plugin and choose 'OSGI Framework' as the target.

You do not need neither an activator nor any advanced stuff like RCP plugin.

Just create a basic OSGi project. And name it org.eclipse.ecr.mysite.

Creating a JAX-RS Application

You should have some knowledge of JAX-RS to understand this part (see the JAX-RS chapter of the Java EE 66 tutorial if you need to get started on JAX-RS).

To have something visible through the HTTP server exposed by ECR, you need to create a new JAX-RS application and declare it in your MANIFEST.MF.

Create a new JAX-RS Application class: org.eclipse.ecr.sample.mysite.MyApp. It will expose a JAX-RS root resource: org.eclipse.ecr.sample.mysite.MyRoot.

Here the content of these two classes:

org.eclipse.ecr.sample.mysite.MyApp

public class MyApp extends Application {

    @Override
    public Set<Class<?>> getClasses() {
        HashSet<Class<?>> set = new HashSet<Class<?>>();
        set.add(MyRoot.class);
        return set;
    }
}

Note: You will need to import the javax.ws.rs.core package in your manifest to compile the code.

org.eclipse.ecr.sample.mysite.MyRoot

@Path("mysite")
@Produces("text/html")
public class MyRoot {
    @GET
    public String doGet() {
        return "Hello World!";
    }
}

Note: You will need to import the javax.ws.rs package in your manifest to compile the code.

Declare the JAX-RS application in your MANIFEST.MF

Add the following line to your manifest: Nuxeo-WebModule: org.eclipse.ecr.sample.mysite.MyApp

ECR will automatically deploy yopur JAX-RS application at startup.

Just start the ECR application in Eclipse (as described in ECR github site) and connect to http://localhost:8080/ecr/mysite. Note that you will be asked to provide an username and a password. Use: Administrator/Administrator.

Note: mysite is the path of your root resource and is installed at the root od ECR server.

Hot reloading your plugin

Now, lets say you want to modify your MyRoot class and test the changes without restarting the ECR server.

Replace the "Hello World!" message by "Hello World Reloaded!", go to the OSGI console and execute:

ss org.eclipse.ecr.sample.mysite

You will see the plugin ID displayed. Run:

refresh {ID}

where {ID} is the ID of your plugin (it should be a number).

Now go back to your browser and refresh the page. You should see the new message.