(Re)using pom metadata
Most of the time I see that people configure WCB metadata like name and description through the OSGi plugin properties in the pom.xml as shown in the code sample below.
<project>
...
<plugin>
<groupId>org.apache.felix.plugins</groupId>
<artifactId>maven-osgi-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<osgiManifest>
<bundleActivator>foo.bar.Activator</bundleActivator>
<bundleName>Foo Bar Component</bundleName>
<bundleDescription>A very nice component...</bundleDescription>
</osgiManifest>
</configuration>
</plugin>
...
This is ok! But, at the same time the main pom.name and pom.description are left undefined most of the time. This is not ok, because now you don't have a proper name or description when you render the site or a different report.
So why not put in a nice pom.name and pom.description and just re-use those in the OSGi plugin configuration as show in the code sample below!?
<project>
...
<name>Foo Bar Component</name>
<description>A very nice component...</description>
...
<plugin>
<groupId>org.apache.felix.plugins</groupId>
<artifactId>maven-osgi-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<osgiManifest>
<bundleActivator>foo.bar.Activator</bundleActivator>
<bundleName>${pom.name}</bundleName>
<bundleDescription>${pom.description}</bundleDescription>
</osgiManifest>
</configuration>
</plugin>
...
In fact this is already the default behavior that is configured in the webmanager-wcbs parent artifact so , if you are happy with the defaults, all you really need to specify is the activator and you are done :)
Installing a 3rd party librarySomething entirely different is the case where you need a 3rd party Java library in your WCB code. This JAR file is probably not readily available in the GX Webmanager SDK and as that is configured to build offline by default you may need to install the jar file in your local repository. Using the standard Maven install plugin this is a piece of cake! The command below shows how I deployed a Google code library into my local repository so I could use it in a WCB.
mvn -s settings.xml install:install-file -Dfile=kaptcha-2.1.jar
-DgroupId=com.google.code -DartifactId=kaptcha
-Dversion=2.1 -Dpackaging=jar
Note: Using a system scope dependency is also possible but I consider that to be kind of a hack ;)
Now if you went ahead and tried the previous example with a standard GX WebManager SDK it probably failed. Why, because the Maven install plugin itself is not included in the offline repository. Here we have a small chicken & egg problem as we can not install the install plugin without the install plugin if you get what I mean :) Bottom line, it is all very nice that the SDK builds offline by default but sometimes you just want to pull in some artifacts and their transitive dependencies. Assuming you have an internet connection, two simple steps to make that work.
1) Tell Maven it should be online by setting this property from false to true in the settings.xml
2) Remove the (plugin)Repository mappings to the local filesystem for central the main pom.xml
A feature many WCB developers already discovered (and love) is the possibility to use the Maven antrun plugin to copy a WCB to the hot deploy directly from the build automatically. Unfortunately, most of the time people just put that configuration in the pom.xml with user specific settings (eg. the path on disk) in such a way that it will also be executed when someone else just wants to do a simple package or so.
The configuration below shows how to configure this just using buildtime properties so that it will work not just on your own filesystem layout. And even more important it enclosed the configuration in a dedicated deploy-local profile so that it can easily be executing when required but will not run by default. I consider this be a nice approach and propose to use 'deploy-local' as a convention!
<project>
...
<profiles>
<profile>
<id>deploy-local</id>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<copy file="${project.build.directory}\${pom.build.finalName}.jar"
todir="${webmanager.wcbdeploydir}" overwrite="true" />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
So that where just some tips & tricks for now.. till next time
Bram
|
|
patricka | 25-06-2008 16:22
So why not put in a nice pom.name and pom.description and just re-use those in the OSGi plugin configuration as show in the code sample below!? |
Bram de Kruijff is Product Architect and one of the co-architects of the GX WebManager framework with a focus on OSGi and services framework. Bram is part of the NAF Web 2.0 forum group to define standards on community technologies.
Other blog entries: