Showing posts with label maven2. Show all posts
Showing posts with label maven2. Show all posts

Thursday, May 22, 2008

Using Maven to build your custom widgetset

In a previous entry, I explained how to set up Maven & ItMill Toolkit for them to work together.

It is also possible to use Maven to automatically build your custom widgets during its compile phase.

That was one a few things that I did not like in the toolkit: each time you want to build your widget, to create the html & js files needed, you have to launch a specific ANT file. Having two separate build mechanisms in a single project... Well, that was not to my taste.
But Maven is Jack of all trade, and is willing to execute any ANT task - if you ask nicely.

For detailed informations on the Maven ANT Run plugin, refer to the official documentation: http://maven.apache.org/plugins/maven-antrun-plugin/

To build the widget located on com.your.company.widget.widgetset , insert the following XML snipset in
your pom.xml :


<project>
...
<build>
<plugins>
...
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>compile</phase>
<configuration>
<tasks>
<property name="compile_classpath" refid="maven.compile.classpath"/>
<property name="client-side-src-location" value="${project.build.sourceDirectory}" />
<property name="client-side-destination"
value="${project.build.directory}\${artifactId}-${version}/ITMILL/widgetsets" />
<path id="compile.classpath">
<pathelement path="${client-side-src-location}" />
<pathelement path="${compile_classpath}"/>
</path>
<java classname="com.google.gwt.dev.GWTCompiler"
failonerror="yes" fork="yes" maxmemory="128m">
<arg value="-out" />
<arg value="${client-side-destination}" />
<arg value="com.your.company.widget.widgetset" />
<classpath>
<path refid="compile.classpath"/>
</classpath>
</java>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>


What this code do is quite simple:
- Tell Maven that it must be executed in the compile phase
- Specify the properties needed by the ANT task, such as the libraries classpath, the source location & the output folder (using Maven global variables to ensure compatibility)
- Specify the ANT task itself, ie. the GWT compiler

As it is done, the resulting files will be put in the appropriate target folder, ensuring that those files will be accessible from the deployed application, included in the WAR file, and cleaned with the rest of the sources when asked via mvn clean.

Tuesday, January 8, 2008

ITMill Toolkit 5 & Maven2

Using ITMill Toolkit 5 & Maven2 together is a matter of minutes.

You do not know or use Maven2 ? And you are developing a Java Web (or not) Project ? What a shame ! You should.
Maven2 allow you to manage your project dependencies, build, and reporting in an easy and cool way. I will not spend too much time detailing Maven2 use here, check http://maven.apache.org/ if you want to know more.

As ITMill Toolkit (gosh, I need an acronym for that ^^), from the developer point of view, is a totally classic web application, nothing special is required to unleash the power of Maven2 on it.

Before anything else, download ITMill jar file . The jar is inside all this stuff, as this is a demo application, in WEB-INF/lib .
Install it in your local Maven2 repository:
mvn install:install-file
-Dfile=
-DgroupId=itmill
-DartifactId=
itmill-toolkit
-Dversion=5.0.0
-Dpackaging=jar
-DgeneratePom=true
Then, create a Maven web project, using the archetype:
mvn archetype:create
-DarchetypeGroupId=org.apache.maven.archetype
-DarchetypeArtifactId=maven-archetype-webapp
-DarchetypeVersion=1.0-SNAPSHOT
-DgroupId=your.company
-DartifactId=project-name
-Dversion=1.0
-Dpackaging=war
Open the project in your favorite IDE (I'm a huge supporter of NetBean6, but I'm sure using Eclipse change nothing).
Edit you project pom.xml . Add the ITMill dependency:
<project>
..
<dependencies>
..
<dependency>
<groupid>itmill</groupid>
<artifactid>itmill-toolkit</artifactid>
<version>5.0.0</version>
</dependency>
</dependencies>
</project>
And there, everything is done.

Just set up a main ITMill class, update your web.xml to add a servlet & servlet mapping for it, and your Maven2 / ITMill project is fully operational.