Sign in

E-mail *, (xx@domain.com)
Password *

Register | Forgot password

Blogs

  • Bram de Kruijff
  • Ivo Ladage
  • Mark van Cuijk
  • Martin van Mierloo
  • Martijn van Berkum
  • Michel Teunissen
  • Patrick Atoon

Recent blogs

RSS - Blogs
March 9, 2010
State of OSGi in the Java world
March 4, 2010
Reach more people with Google Translate
March 3, 2010
Get My Advice
February 26, 2010
What? Where!?!
February 11, 2010
Split it!

All Blogs...


A few SDK tips & tricks

June 3, 2008

While doing some code reviews on WCBs I ran into some common issues that developers encounter while doing development. Just a few tips & tricks..


(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 library

Something 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 ;)

Doing an online build

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


Using antrun for auto deployment

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

About the Author

Return to all blogs


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.

Read all Brams blog entries

Other blog entries:

June 26, 2009
Presentation at NAF Insight WEB 2.0
April 21, 2009
GX WebManager 9.8 on Java SE 6: The right stuff!
April 17, 2009
dOSGi talk at JSpring 2009
March 5, 2009
Accessing services in GX WebManager
May 29, 2008
Maven secrets: Dynamic Maven properties with Beanshell
May 27, 2008
GX WebManager on SpringSource Application Platform
May 9, 2008
JavaOne 2008 wrapup
April 14, 2008
Maven secrets: assembling a WCB zip
April 11, 2008
ApacheCon EU 2008 impressions
April 4, 2008
OSGi techtalk at JTeam


Share:

del.icio.us
digg
Technorati
Slashdot
Reddit
YahooMyWeb
NewsVine
ekudos
© 2010 GX creative online development B.V.

Disclaimer

This website (GXdeveloperweb.com) may discuss or contain opinions, (sample) coding, software or other information that does not include GX official interfaces, instructions or guidelines and therefore is not supported by GX. Changes made based on this information are not supported.  GX will not be held liable for any damages caused by using or misusing the information, software, instructions, code or methods suggested on this website, and anyone using these methods does so at his/her own risk. GX offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this website, including any liability resulting from incompatibility between the content of this website and the materials and services offered by GX. By using this website you will not hold, or seek to hold, GX responsible or liable with respect to the content of this website.