Archive for the ‘Java’ Category.

Building an Eclipse Plugin with Maven ?

Apache Maven is great for building java application, it is especially good at dealing at project dependencies and the way they are used and packaged with a project. In the world of the Java applications there is also the guys who play it differently. OSGI based applications don’t deal with dependencies like any other “classical” java projects. For instance when you have a dependency in OSGI you can’t access all the classes of this dependency but only those for which the package has been exposed… This difference between classical and osgi app make difficult building an Eclipse RCP application 100% with maven. More exactly it was so easy to build it with their specific generated ant script, that it was rarely worth it.

This lengthy article at Eclipse Corner, is describing in great details how to build/test an Eclipse plugin with maven. It covers in depth how maven2 works, how eclipse works and what to do to make them work together effectively.

I’ve yet to try their solution which is almost solely based on custom plugins they have written to perform this specific task. I know that the maven team is also working towards supporting OSGI’s way of handling dependencies out of the box. There is also a plugin at codehaus which handles building Eclipse application from maven 2.

Links :

Maven 2.0.5 is out.

Almost 1 year after the previous release ( 2.0.4 was out in april 2006), Maven 2.0.5 is out today bringing a little bit more than 80 bug fixes/enhancements.

I’ve tested the latest rc and all the various builds I’m running are working fine, but some changes included in this release could affect your build and are worth noticing in the release notes.

Links :

Java Module System Presentation

The Java Module System (JSR-277) aims to describe what will be the future of the actual jar file format and where and how to store them. They try to define a new way of describing a piece of code in java (jar, ear, war etc..) and how to store and retrieve them, so almost every developer is going to be impacted by their work. I’ve always been keen of following this JSR in particular, since it has probably a lot in common with what OSGi is going to be and on the other side it’s directly impacting what maven is defining.

InfoQ has recently displayed a presentation describing this JSR in details, the talk is animated by the specification leader.

I finally took some time last night to watch it (ok it’s 50 minutes long, but if you can watch only the first 5 minutes you’ll understand roughly what they are preparing), it’s well worth it considering you’ll probably be impacted sooner or later to what those guys are defining now.

Links :

JavaNCSS Maven Plugin 2.0-beta-2 release.

The javancss-maven-plugin for maven 2 has been released today.

This plugin allows user to:

  • Compute complexity (CCN) and quantity (NCSS) metrics on your code
  • Create a report displaying those number.
  • fails the build when the complexity or quantity metrics goes beyond a threshold.

The plugin is based on the javancss tool available already as a standalone tool and a ant task (but who’s using ant nowadays :P ).

This version is almost final, since there is no plan to add huge features, unless you request it…
The plugin is sync at codehaus repository and ibiblio at least for now.
To use it in your maven build you have only to add :

<project>
  ...
  <reporting>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>javancss-maven-plugin</artifactId>
        <version>2.0-beta-2</version>
      </plugin>
    </plugins>
  </reporting>
  ...
</project>

Full documentation is available at mojo web site.
Bug reports and the like can be reported in codehaus Jira.

There’ve been quite a few bug fixes since last release back in june 06.
Here’s the release notes :
Bug

  • [MJNCSS-7] – Profanity in generated report
  • [MJNCSS-8] – NullPointerException when report are generated on … Windows
  • [MJNCSS-10] – Plugin crashes when Java elements have special characters

Improvement

  • [MJNCSS-2] – javancss-maven-plugin JXR integration
  • [MJNCSS-3] – exclude directory
  • [MJNCSS-4] – JavaNCSS may not fully support 1.5 annotations
  • [MJNCSS-5] – Drop Function and replace by Method where applicable in reports
  • [MJNCSS-6] – Make plugin documenation standard with docck.

New Feature

  • [MJNCSS-1] – Create javancss:check mojo

xFunction calls native code… sometimes.

I was upgrading a Java application which must call some native code at some point.
Our application is targeted to run on Windows platform and MacOSX. The company I’m working with has bought Excelsior xFunction. This library aims to ease calling native libraries from java application, and it succeed pretty well. It comes as a standard Java jar archive and a native library for each platform ( xFunction.dll, or dylib or .so depending of the target operating system to run the application on).

The developers on the project knows already how to use the library, they’re even pretty familiar with it.
Besides this, on this specific project, we only have to call a pair of native functions which returns pretty classic arguments. Nothing hard to do.

A perfect and easy job for xFunction. Or so I thought…
We wrote our code, built the various distribution thanks to our maven 2 build with the use of profiles and then… we discovered the xFunction library on macOSX is only available compiled for powerPC platform. Running it on a intel based Macintosh seems not possible, the JVM running the java code is x86 code. Macintosh comes with some kind of emulator called Rosetta which seamlessly execute ppc code on a x86 machine, but it seems you can’t load a powerpc library from x86 code.

I’m far from being an expert, but it sounds easy to me, to make the xFunction library available on intel platform maybe just to … recompile it, and that’s all. So we send an email to the company making xFunction… and here’s what they reply to us :

…/…

Unfortunately, we have not version of xFunction for Mac OS X that runs on Mac-Intel box.

However, it is possible to hasten the development on the basis of custom projects, with some sharing of costs. If you’re interested, please contact our Sales Dept. at mailto:sales@excelsior-usa.com

Regards,

…/…

Here I did have but two choice, either argue by email with their sales dept :p or … drop XFunction out of the project and replace it by our own code.

Well, we dropped xFunction out because at least we won’t get stuck in the future being force to call a sales dept… :p
This is interesting also, from the open source point of view. I mean, If I did have the source of xFunction, it was a matter of a couple of hours to rebuild and perform some tests on it.

Having the JDK sources in Eclipse on MacOSX

src.jar image

I switched to a pretty MacBook for something like 2 weeks now, I’m still learning how to use MacOSX properly and found my way in most challenges up to now.

But I stumbled upon having the JDK sources inside Eclipse. I mean viewing the source code of the java.lang.String class for instance.
On a windows or linux environment, once you know where to look it’s pretty simple, in the preferences menu inside Java->Installed JREs you have to change the JRE to a JDK. Of course you must have installed the sources when you installed the jdk, but this option is checked by default, so chances are you already have the sources.

But as on MacOSX, if I’m not mistaken, Apple is providing the JDK not Sun directly, you don’t have to install it yourself, it’s already installed for you. Pretty decent. But I couldn’t get a hold on the sources. The solution is pretty simple… they are not there. You have to install yourself the documentation which contains the sources.

  1. Quit Eclipse
  2. Download & install the JDK documentation which can be found at http://developper.apple.com/java/download.
  3. Launch Eclipse.
  4. F3 on the first String in your code… Tadaaa

Here you are :)
Source location can be found locally in your system in /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home/src.jar

I didn’t find it myself, thanks to David Gageot for the tip !

Archiva…

A quick post on Maven Archiva (former Maven Repository Manager):

  • It seems to be included in the latest Maestro release offered by Mergere. (I didn’t try it out).
  • All of a sudden yesterday, my running archiva application popped a lots of outofmemory errors. So I checked out the latest sources, and tried to build the latest version. Unfortunatly I can’t make it to work. I have still to try it on a clean machine to check if it’s the environnement or the current state of the sources.

Maven Archiva (2/2)

Maven Archiva can play the role of proxy for all public maven repositories and your company own repositories, all through one host.
This feature bring many advantages :

  • This cut down each developer specific maven settings to hold only one repository.
  • You don’t suffer much of a slow repository for artifacts you already have, while building projects.
  • Enabling snapshots dependencies can be made for the whole team, without having to update all settings.xml on each developer workstation.

For instance, before maven Archiva my configuration in ~/.m2/settings.xml was :

     <profile>      <id>maven-repo</id>      <repositories>        <repository>          <id>central</id>          <name>default outbound repository</name>          <url>http://repo1.maven.org/maven2</url>        </repository>        <repository>          <id>CodeHaus</id>          <name>CodeHaus SnapShots</name>          <url>http://snapshots.maven.codehaus.org/maven2</url>        </repository>        <repository>          <id>ibiblio</id>          <name>ibiblio public repository</name>          <url>http://ibiblio.org/maven2</url>        </repository>      </repositories>      <pluginRepositories>        <pluginRepository>          <id>CodeHaus</id>          <name>CodeHaus</name>          <url>http://snapshots.maven.codehaus.org/maven2</url>        </pluginRepository>      </pluginRepositories>     </profile> 

now :

     <profile>      <id>archiva</id>      <repositories>        <repository>          <id>archiva</id>          <name>Archiva</name>          <url>http://tux6.vidal.net/archiva</url>        </repository>      </repositories>      <pluginRepositories>        <pluginRepository>          <id>archiva-plugin</id>          <name>Archiva</name>          <url>http://tux6.vidal.net/archiva</url>        </pluginRepository>      </pluginRepositories>     </profile> 

Thanks to Maven Archiva configuration :

Reminder : I build daily maven archiva, it seems to be still in development and no release are out.
You have to build it manually and put the web app built in your favorite j2ee container.