Over a million developers have joined DZone.

Glassfish And OSGI Part I : A Look Into Glassfish V3 Development With Eclipse 3.4

DZone's Guide to

Glassfish And OSGI Part I : A Look Into Glassfish V3 Development With Eclipse 3.4

· Java Zone
Free Resource

Download Microservices for Java Developers: A hands-on introduction to frameworks and containers. Brought to you in partnership with Red Hat.

The Glassfish V3 Architecture adopted the Felix OSGI Runtime as a microcontainer. In a series of articles, I will look into the “Glassfish and OSGI”. The aim of this is to research  how to adopt OSGI as an application server’s microcontainer. As a middleware developer,firstly, I pay more attention to the building of development environments. In this article, I will show how to use Eclipse 3.4 as your Glassfish V3 Development Platform based on my experience.

Preparing Tools Related To V3 Building and Development

  • J2SE 6

    Download  J2SE 6 From http://java.sun.com/javase/downloads/index.jsp , and set the JAVA_HOME and system path environment variables.
  • SVN

    Download Tortoise SVN from http://tortoisesvn.tigris.org/. Add the svn executable command to System Path environment variable. Note: if you are using the private network(or are behind a proxy server), you must configure the SVN Network Settings.
  • Maven 2

    Download Maven 2.1.0 from http://maven.apache.org/download.html ,and configure Maven 2 according to Installation Instructions on Maven Site. Note: if you are using the private network(or are behind aproxy server), you must configure the  “Proxy” element in the $Maven_HOME/conf/setting.xml.
  • Eclipse

    Download Eclipse 3.4 from http://www.eclipse.org/downloads/ .
  • Eclipse Plug-In

    Because Glassfish V3 is fully integrated with Maven 2, and if you are using the Maven 2 Eclipse Plug-in, integration between Glassfish v3 and Eclipse will be more friendly. You can use the Maven 2 Plug-in to observe the dependencies between the OSGI Bundles clearly. I recommend installing M2Eclipse Plug-in from http://m2eclipse.sonatype.org/update using Eclipse’s Update Manager.


Check out Glassfish V3 SRC

Open the command shell, or use the Tortoise SVN Graphical Tool, to execute the following command:

svn checkout https://svn.dev.java.net/svn/glassfish-svn/trunk/v3

Generating V3 Project File of the Eclipse IDE

For this step I first referred to the following instructions:  http://wiki.glassfish.java.net/Wiki.jsp?page=V3DevelopmentInstructions

Open the command shell and locate the GlassFish v3 src home directory which is checked out using 2 step. Then, execute the following command:

mvn -DdownloadSources=true eclipse:eclipse

If there are no problems, you will see the following result.

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] ------------------------------------------------------------------------
[INFO] GlassFish Parent Project .............................. SUCCESS [12.234s]
[INFO] Super POM for Java EE API modules ..................... SUCCESS [3.937s]
[INFO] javax.enterprise.deploy API v.1.2 ..................... SUCCESS [0.625s]
[INFO] javax.transaction API v.1.1 ........................... SUCCESS [0.203s]
[INFO] Java EE API modules repackaged as OSGi bundles in GlassFish SUCCESS [0.0 32s]
[INFO] Glassfish Full Bundle ................................. SUCCESS [57.813s]
[INFO] Embedded GlassFish .................................... SUCCESS [0.016s]
[INFO] Embedded GlassFish API ................................ SUCCESS [11.031s]
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4 minutes 59 seconds
[INFO] Finished at: Tue Mar 24 10:16:51 CST 2009
[INFO] Final Memory: 75M/254M
[INFO] ------------------------------------------------------------------------

You have just generated the V3 Eclipse Project File( .project file) successfully, and you can locate the GlassFish v3 src sub directory(eg, V3_SRC\admin\cli) and find the .project file.

Import V3 Module into Eclipse

At this time, you can import V3 Module into Eclipse by clicking the File->Import->…. Then, you can use M2Eclipse Plug-In to “Enable Dependency Management”. M2Eclipse can use M2_REPO to load OSGI Bundles from Maven Local Repository(By default, M2_REPO is ~/.m2/repository).

Then, you can browse and develop your custom function in the Eclipse JDT. The following picture is my v3 development environment after successful configuration.

A good feature of M2Eclipse is that you can see the dependency relations between OSGI Bundles clearly.Please see the following picture:

Notes to be Discussed


  • Compile Modified Code

    I have tried compiling the modified code(eg. Admin Cli module) using the “Maven Compile” Phase integrated in the Eclipse JDT(which is supported by M2Eclipse). However, The result is not as expected. The following compile error appears:

    Artifact-Id: admin-cli
    Version: 3.0-SNAPSHOT
    From file: E:\workspace\IBAS\Education\ApplicationServer\glassfishV3\Build\V3_SRC\admin\cli\pom.xml

    Reason: Unable to lookup component 'org.apache.maven.plugin.Mojo', it could not be created. role: org.apache.maven.plugin.Mojo roleHint: com.sun.enterprise:hk2-maven-plugin:0.3.48:hk2-compile classRealm: /plugins/com.sun.enterprise:hk2-maven-plugin:0.3.48@48/thread:main

    Root cause: com.sun.mirror.apt.AnnotationProcessorFactory

    I think that it is a bug in M2Eclipse. So, I decided to compile the modified code in the command shell. I located  the Admin CLI Module Directory and executed the “Maven Compile” from there, and compile is successful!

    Does anyone have any suggestions for this problem. How can you compile and debug a V3 Module in the Eclipse JDT?
  • Build V3 Code

    I should to point out that if you are building V3 behind the proxy server or suffering from file size bandwidth limitations , you may need to download some zip/bundle files manually and place these bundles into your local maven repository(By default, M2_REPO is ~/.m2/repository).

I will dicuss the GlassFish v3 module’s building lifecycle in the next article.

Download Building Reactive Microservices in Java: Asynchronous and Event-Based Application Design. Brought to you in partnership with Red Hat


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}