Friday, January 04, 2008

Maven, rmic-maven-plugin and the Ant task

This is a Java tech post, not the type I usually include here, but I spent a lot of time searching for the solution and I wanted to share my findings.

I'm migrating a project at work from Ant to Maven and needed to RMI Compile (rmic) some classes.

There appear to be a couple options: Using a Maven Plugin, rmic-maven-plugin, http://mojo.codehaus.org/rmic-maven-plugin or using the rmic Ant task. The plugin is not very well documented and is still in an Alpha-SNAPSHOT version. The Ant task works great.

I found some direction on using the task from Maven from here: http://jira.codehaus.org/browse/MANTRUN-23

If you don't setup the dependencies for the maven-antrun-plugin, you'll end up with this error:
"Cannot use SUN rmic, as it is not available. A common solution is to
set the environment variable JAVA_HOME or CLASSPATH."

Below is a snippet from my pom.xml file.


<project>
.
.
.
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<dependencies>
<!-- runtime dependency for the antrun plugin.
It brings tools.jar into the plugins execution
space so the 'rmic' compiler can be called from
Ant's <rmic/> task.
-->
<dependency>
<groupId>sun</groupId>
<artifactId>tools</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>
${java.home}/../lib/tools.jar
</systemPath>
</dependency>
</dependencies>
<executions>
<execution>
<id>rmic</id>
<phase>compile</phase>
<configuration>
<tasks>
<rmic verify="true" debug="on"
classpathref="maven.compile.classpath"
base="${project.build.directory}/classes"
includes="**/Remote*Impl.class"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

1 comment:

Anonymous said...

Thank you a lot.. very useful