-
Notifications
You must be signed in to change notification settings - Fork 6
Hello World Plugin
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
.
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:
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.
@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.
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.
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.