Jump to: navigation, search

Difference between revisions of "Jetty/Tutorial/Jetty-OSGi SDK"

Line 14: Line 14:
 
Choose either of those methods.
 
Choose either of those methods.
  
* With eclipse-PDE-3.6: Download [http://download.eclipse.org/eclipse/downloads/drops/R-3.5.1-200909170800/index.php] or more recent.
+
* With eclipse-PDE-3.6: Download Eclipse-3.6M5-SDK or Eclipse-3.6M5-EE or more recent.
Use the update UI and define the new site http://www.intalio.org/public/maven2/org/intalio/osgi/updatesite-3.6/
+
Use the install UI and define the new site http://www.intalio.org/public/maven2/org/intalio/osgi/updatesite-7.0.2.v20100331-03/
  
 
* With eclipse-PDE-3.5: Download [http://download.eclipse.org/eclipse/downloads/drops/R-3.5.1-200909170800/index.php] or more recent.
 
* With eclipse-PDE-3.5: Download [http://download.eclipse.org/eclipse/downloads/drops/R-3.5.1-200909170800/index.php] or more recent.
 
Use the update UI and define the new site http://www.intalio.org/public/maven2/org/intalio/osgi/updatesite-3.5/
 
Use the update UI and define the new site http://www.intalio.org/public/maven2/org/intalio/osgi/updatesite-3.5/
 
* You can also choose to download the zip of the corresponding features and install them in dropins:
 
http://www.intalio.org/public/maven2/org/intalio/osgi/org.intalio.osgi-packages-hightide.features.sdk/7.0.1.009
 
  
 
=== First web-application defined in an OSGi bundle (RFC66) ===
 
=== First web-application defined in an OSGi bundle (RFC66) ===

Revision as of 07:06, 8 April 2010



Introduction

Jetty-OSGi SDK extends the Plugin Development Environment (PDE) to support the debugging of web-applications.

The "Jetty" launch configuration prepares the execution of jetty-osgi and deploys web-applications on it. The web-applications are either defined as pure java projects or as OSGi bundles. The SDK also provides two project templates suitable to create web-applications embedded inside an OSGi bundle.


Why use Jetty-OSGi-SDK if OSGi is not the concern?

  • In-place Debugging: jetty-osgi will pick-up the classes and files where eclipse puts them; faster, simpler hot swapping of bytecode compliment of eclipse.
  • Multiple web-applications at once can be debugged. A UI let you select what projects you want to debug.
  • Unconstrained configuration of the application-server: Jetty-OSGi is started and configured just like a standard jetty-hightide server. The fact that this happens inside an OSGi container is an implementation detail.
  • Debug your web-applications at the same time than other web-applications that are not setup in the IDE: say you need to debug the integration of your web-application with a Single-Sign-On webapp like cas. Place cas.war inside ${jetty.home}/webapps and voila.

Installation

Choose either of those methods.

  • With eclipse-PDE-3.6: Download Eclipse-3.6M5-SDK or Eclipse-3.6M5-EE or more recent.

Use the install UI and define the new site http://www.intalio.org/public/maven2/org/intalio/osgi/updatesite-7.0.2.v20100331-03/

  • With eclipse-PDE-3.5: Download [1] or more recent.

Use the update UI and define the new site http://www.intalio.org/public/maven2/org/intalio/osgi/updatesite-3.5/

First web-application defined in an OSGi bundle (RFC66)


Create a new OSGi Project

Create a new Plug-in Project

OSGi Project name

Choose 'OSGi bundle'

OSGi Project parameters

Choose 'Next' instead of 'Finish' to show the project templates.

OSGi Project RFC66 template

Choose the 'Jetty RFC66' template.

Web-application parameters

The web-bundle generated.

Right-click and choose run as...

Right-click on the project and choose "Run as... Jetty-on-OSGi"

Open a web-browser and check.

Open a web-browser and check that the webapp is running. Everything is configured by default at this point: jetty is running on localhost at port 8080.

Launch configuration

Run Configuration.

To customize the configuration of jetty used to run this web-application, choose the menu "Run configuration..." and select the "Launch Jetty in OSGi" node. The first tab "Jetty Configuration" points to the default jetty.home folder. Jetty-on-OSGi uses a folder hierarchy inside which it locates the configuration file(s) (${jetty.home}/etc/jetty.xml), the configuration for the central logging (${jetty.home}/resources/logback.xml). By default the SDK will generate the jetty.home folder in the PDE runtime workspace and will place the default configuration files identical to the ones distributed with jetty.

The wizard gives direct access to jetty.xml but other settings should be done by accessing the file system. (TODO: improve; for example provide a wizard to import as a project a jetty configuration so that everything can be done from eclipse.)



Debugging web-applications defined in standard java projects

CAS a java project

A very common situation is to have a set of existing java projects that define a web-application. The SDK is able to deploy them and execute them just like an RFC66 web-bundle.

Let's take a java project that defines a web-application: it contains a folder 'webapp' inside which jsp pages and WEB-INF/web.xml are located.

Jetty-OSGi won't run this as an OSGi bundle: it depends on a set of jars that are outside of the platform and eventually on other java projects.

Jetty-OSGi only needs to recognize the webapp folder and to know what is the servlet context to use. The current approach consists of adding a META-INF/MANIFEST.MF file to the project and to use the headers that jetty-osgi would use for an OSGi web-application:

Web-ContextPath: /cas
will set the context path to "/cas"
Jetty-WarFolderPath: /src/main/webapp

In fact by default Jetty-WarFolderPath is assumed to be '/src/main/webapp' and the context path is the name of the eclipse project.

It would be nice to support more sophisticated ways of identifying a java project that contains a web-application: WTP and maven's pom.xml file come to mind.


Choose the java projects to deploy as webapps

The Jetty Configuration tab displays the java projects that are identified as web-applications. The checkbox selects the projects to be debugged as web-applications. Libraries and java projects on which they eventually depend don't need to be configured. A list of the OSGi web-bundles is also displayed.

TODO: more doc. Although the java project is not an OSGi project, it is possible to inject OSGi dependencies: Use the Require-Bundle or the Import-Package in the manifest and add to the .classpath the line:

<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>

This is very useful to gradually migrate java projects to OSGi bundles: not all libraries need to be OSGi ready. Partially migrated libs are fine during development.


Developing Jetty-OSGi in PDE

Use the jetty-sdk setup; identical to the one used for the development of web-applications. Import as project the bundles to work on: [2]

Start hacking using the PDE just like any other OSGi bundle or eclipse plugin. Launch using the jetty configuration. The PDE will use the bundles as defined in the workspace as a replacement for the jetty bundles.

Additional Resources

Jetty-OSGi, RFC66, PDE We are working on migrating all building an update site and executing the build on eclipse with the rest of the jetty@eclipse project. In the mean time, the latest code is here: [http://github.com/intalio/hightide-on-osgi