Virgo has been delivered with several sample applications used by many newbies creating their first OSGi running application. One of the flagships from the Virgo sample pool of applications is the Greenpages application.  Greenpages has several issues preventing developers from using it from within Eclipse. Although most of the issues have been identified so far some of them cannot be solved by patching the application but rather by tweaking the environment. Sprinsource developers patched the application and released Greenpages 3.0.0 RC1 . Consequently this new guide has been released for to support Greenpages within Eclipse development environment. This document retires another guide associated with Greenpages 2.5.0 release.

Introduction

The list of components required to follow this guideline:

  • Spring Tool Suite 3.1.0.RELEASE (STS) – based on
    • Eclipse Juno 4.2.1,
    • Java 1.7 and
    • M2E 1.3.1
  • Eclipse Virgo IDE 1.0.0
  • Virgo Tomcat Server 3.6.0.RELEASE

This guide assumes your intermediate level of skills about the products referenced. Please refer to product manuals and Greenpages documentation in order to set up products and follow the guide. Beside resolving Greenpage application deployment issues the guide also brings two upgrades:

  • Java will be upgraded to version 1.7
  • Spring version will be upgraded to 3.1

STEP 1: Importing Greenpages 3.0.0

Download and unzip samples-3.0.0.RC1.zip into temporary folder. Open STS and perform Import all Existing projects into Workspace from a temporary folder. Check option to copy Greenpages projects into workspace. Convert all legacy Maven projects. Several error notifications pop up in the Problems view. They will be resolved during next steps.

STEP 2: Balance Java Versions

Let’s start with fixing errors “‘Java compiler level does not match the version of the installed Java project facet.” Problem is associated with Greenpages.core, Greenpages.db, greenpages.jpa and Greenpages.web. Eclipse’s Quick Fix suggests either to upgrade Java compiler version to 1.6 or Java project facet version to Java 1.7. Greenpages.parent pom.xml is based on Java 1.5.  Java sources and classes will be migrated 1.7.

NOTE: Projects could also be upgraded to Java 1.6. This final result has only been verified for migration to Java 1.7.

First, perform Maven-Update-Project from the context menu and select all the projects. Notice the significant reduction of errors in the Problems view.

Second, open Greenpages.parent/pom.xml and update source and target version numbers.

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-compiler-plugin</artifactId>
	<version>2.3.2</version>
	<configuration>
		<source>1.7</source>
		<target>1.7</target>
	</configuration>
</plugin>

Perform Maven-Update-Project from the context menu and select all the projects. Notice the significant reduction of errors in the Problems view.

In case of migration to Java 1.7, you need to update the Virgo runtime configuration.

This extra task is required to override EclipseLink Bug 339388: Bytecode weaving has issues with JDK 7. Open Virgo Web Server configuration by opening Virgo Runtime at localhost – Overview – Open launch configuration. Add VM argument -XX:-UseSplitVerifier.

STEP 3: Upgrading Spring Framework Version to 3.1.0

This step is necessary because of the Spring version gap between Greenpages 3.0.0 ( based on two Spring  3.0.5 components) and Virgo 3.6.0 (based on Spring 3.1.0). The gap is resolved by upgrading Spring version in Maven to 3.1.0.

Open greenpages.parent/pom.xml and update version number for the following dependency:

<dependency>
	<groupId>org.springframework</groupId>
	<artifactId>org.springframework.test</artifactId>
	<version>3.1.0.RELEASE</version>
	<scope>test</scope>
</dependency>

Also Delete another dependency as it is no longer needed:

<dependency>
	<groupId>org.springframework</groupId>
	<artifactId>org.springframework.aspects</artifactId>
	<version>3.0.5.RELEASE</version>
	<scope>test</scope>
</dependency>

STEP 4: Resolving Plexus-Archiver 2.1 Issue

The “org.codehaus.plexus.archiver.jar.Manifest.merge(org.codehaus.plexus.archiver.jar.Manifest)” error message appears because of the maven archiver plugin incompatibility with plexus-archiver-2.1.jar. This issue is thoroughly discussed in github as “sonatype / m2eclipse-extras issue #10”.

Open Greenpages-parent/pom.xml and downgrade the plugin version from 2.4 down to 2.3.2:

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-jar-plugin</artifactId>
	<version>2.3.2</version>
	<configuration>
	   <archive>
		<manifestFile>
			src/main/resources/META-INF/MANIFEST.MF
		</manifestFile>
	   </archive>
	</configuration>
</plugin>

Perform Maven-Update-Project from the context menu for bundles Greenpages.core, Greenpages.db, Greenpages.jpa and Greenpages.web.

STEP 5: Building Greenpages PAR Gradually

Each of Greenpages bundles depends on other OSGi bundles. Some of the bundles have been delivered as native Virgo bundles and others, still need to be identified, downloaded and deployed together with application. During the following steps Greenpages bundles will be reworked and mapped to Virgo. To break down the complexity the application will be disintegrated first and then gradually re-integrated back to PAR project one bundle after another. For each bundle the following reintegration procedure will be performed:

  1. Build bundle with Maven.
  2. Reactivate bundle in PAR Greenpages Maven files.
  3. Build PAR Greenpages with Maven to collect bundle dependencies.
  4. Deploy new bundle dependencies to Virgo user region.
  5. Target bundle to Virgo Runtime.
  6. Enable Bundle Classpath Container.
  7. Add bundle into PAR Greenpages MANIFEST.
  8. Analyze bundle MANIFEST file and perform any changes.

PAR Editor 1

Start with disassembling the application.

Open PAR Greenpages MANIFEST.MF and remove all bundles except G

reenpages.core.

Finally build Greenpages.parent with Maven. This will enable later Maven PAR re-builds.

STEP 6: Mapping Greenpages.core to Virgo

First, build bundle with Maven goal install. Build PAR with Maven goal package.

Please notice from the log that com.springsource.freemarker-2.3.18.jar has already been copied to Greenpages/target/par-provided container. As Maven is ignorant of bundles installed in Virgo’s repositories it dumps these files to par-provided container.  We need to manually filter bundles which are not installed in Virgo yet and copy the spotted jars to Virgo’s usr repository.   So, copy the file that com.springsource.freemarker-2.3.18.jar to Virgo’s usr repository.

Next , we need to map dependencies found in the MANIFEST.MF file to bundles in Virgo repository. Eclipse and Virgo support us by presenting Bundle Dependencies container.  In order to turn on this functionality we need to associate bundle with Virgo Runtime:

Targeted Runtimes

Enable Bundle Classpath Container using Virgo – Enable Bundle Classpath Container while Virgo server is stopped.

Dependent package com.springframework.stereotype  can be found in  bundle org.springframework.context_3.1.0.RELEASE.jar of the Bundle Dependencies container. The bundle is actually located in ext folder of the Virgo Repository as it belongs to native Virgo bundles.  Note also that package version 3.1 falls within the requested interval [3.0, 3.5] defined in MANIFEST.MF.

Now open the file Greenpages.core/src/main/resources/META-INF /MANIFEST.MF. The Virgo Bundlor tool created a list of bundle dependencies relying on template.mf file  and detailed bundle artifact analysis.  You can re-run Bundlor tool and refresh the list using command Virgo – Run Generation of MANFEST.MF File.

Greenpages core  1

Finally start server Virgo Runtime and test Greenpages.core by deploying the PAR Greenpages.

Observe deployment log to confirm absence of errors.  Please notice the implicit deployment of bundle greenpages-3.0.0.RELEASE-com.springsource.org.h2 .

Uninstall PAR and stop the Virgo Runtime server to get ready for the next step.

STEP 7: Mapping Greenpages.db to Virgo

Build bundle with Maven goal install, reactivate bundle in PAR’s POM and build PAR with Maven package. Please notice from the log that the following files have been copied to Greenpages/target/par-provided container:

com.springsource.org.apache.commons.dbcp-1.2.2.osgi.jar
com.springsource.org.apache.commons.pool-1.3.0.jar
com.springsource.org.eclipse.persistence-2.0.0.jar
com.springsource.org.eclipse.persistence.internal.libraries.asm-2.0.0.jar
com.springsource.org.eclipse.persistence.jpa-2.0.0.jar

Mapping the list to Virgo’s repositories reveals we need to copy all these files to Virgo’s usr repository. After copying all these files update Greenpages.db target runtime  to Virgo Runtime and turn on Bundle Dependencies container while Virgo server is stopped.

Re-enable Greenpages.jpa in PAR Greenpages MANIFEST.MF file.

Continue in the same manner as with the Greenpages.core bundle: open Dependencies for Greenpages.db/src/main/resources/META-INF /MANIFEST.MF.

Greenpages db 1

Package javax.sql  is actually exported by  org.eclipse.osgi bundle which is a member of Virgo kernel  region. Unfortunately is not displayed within Bundle Classpath Container. The org.h2 package will be delivered by PAR Greenpages.

Finally start server Virgo Runtime and test Greenpages.db by deploying the PAR Greenpages.

Observe deployment log to confirm absence of any errors.

Uninstall PAR and stop the Virgo Runtime server to get ready for the next step.

STEP 8: Mapping Greenpages.jpa to Virgo

Start with removing the dependency on org.springframework.aspects. Open Greenpages.jpa/pom.xml and remove the following dependency:

<!—Remove this dependency
 <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>org.springframework.aspects</artifactId>
      <scope>provided</scope>
</dependency>  -->

Next, build the bundle with Maven goal install, reactivating bundle in PAR’s POM and building PAR with Maven goal package. Two new dependent bundles are collected in PAR’s target\par-provided container:

com.springsource.javax.validation-1.0.0.GA.jar
com.springsource.org.eclipse.persistence.internal.libraries.antlr-2.0.0.jar

Mapping the list to Virgo’s repositories reveals a need to copy both  files to Virgo’s usr repository. After copying them set Greenpages.jpa target runtime  to Virgo Runtime and turn on Bundle Dependencies container while Virgo server is stopped.

Re-enable Greenpages.jpa in PAR Greenpages MANIFEST.MF file.

Open Dependencies for Greenpages.jpa MANIFEST.MF:

Greenpages jpa 2

Finally start server Virgo Runtime and test Greenpages.jpa by deploying the PAR Greenpages. Observe deployment log to confirm absence of any errors.

Uninstall PAR and stop the Virgo Runtime server to get ready for the next step.

STEP 9: Mapping Greenpages.web to Virgo

Again, start with removing the dependency on org.springframework.aspects. Open Greenpages.jpa/pom.xml and remove the following dependency:

<!—Remove this dependency
<dependency>
   <groupId>org.springframework</groupId>
    <artifactId>org.springframework.aspects</artifactId>
	<scope>test</scope>
</dependency>  -->

Continue with building the bundle with Maven goal install, reactivating bundle in PAR’s POM and building PAR with Maven goal package. No new files have been added to the PAR’s target\par-provided container.

Add Greenpages.web target runtime  to Virgo Runtime and turn on Bundle Dependencies container while Virgo server is stopped.

Re-enable Greenpages.jpa in PAR Greenpages MANIFEST.MF file.

Greenpages.web project has been delivered with Dynamic Web Module project nature. This nature for some reason prevents module to be delivered within greenpages-3.0.0.RELEASE-synthetic.context therefore it has to be removed. Due to another Eclipse issue (NPE) it cannot be removed using Properties – Project Facets  dialog. Fortunately you can use a workaround. Open the file greenpages.web/.settings/org.eclipse.wst.common.project.facet.core.xml you can find  in Navigator view. Remove the line  <installed facet=”jst.web” version=”2.5″/>. The final outlook of the file should be:

<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
    <runtime name="Virgo Runtime"/>
    <installed facet="org.eclipse.virgo.server.bundle" version="1.0"/>
    <installed facet="jst.java" version="1.7"/>
</faceted-project>

Finally start server Virgo Runtime and test Greenpages.web by deploying the PAR Greenpages. Do not forget to starting the H2 database in the first placeObserve deployment log to confirm absence of any errors.

STEP 10: Avoiding Virgo PAR Republishing Issue

By default Virgo server is configured to automatically refresh bundles, PARs and plans every 5 minutes. This automatic refresh appears even without any project modification from developer. There is an issue with PAR and plan refresh.

Cannot refresh par 'greenpages' version '3.0.0.RELEASE' as refresh of par artifacts is not supported.

In order to avoid recurring republishing you need to turn off automatic republishing.

Virgo 1

Conclusion

Application has been re-assembled and can now be deployed to Virgo. Do not forget to start up the H2 database first. Use application compliant version, 1.0.71, of the database driver to avoid database access conflicts from the Greenpages application.

You can override all but the last two steps by simply downloading the final version of Greenpages300.zip. Archive does not contain H2 database so you might still need to download the original sample file containing H2 database and documentation.

Thanks to EclipseRT Virgo Team for significant reducing the issues while upgrading Greenpages from 2.5.0 to 3.0.0.

Advertisements

2 thoughts on “

  1. It is indeed a very good article and helped me a lot but One thing missing is I was getting copy-dependencies not supported by m2e too and I got rid of it by add before plugins in build tag. It is a known issue and plugin management can make compiler to ignore this error.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s