Building jWebUnit with Maven 2

Maven is, just like ant, a build tool. However, where you have to tell ant what it needs to do and how, you only have to tell Maven what you need, if you adhere to the Maven standards.

In order to use Maven to build jWebUnit, you need to have Maven 2 installed. This should not be any more difficult than installing ant. We've included a best practise installation and configuration for Maven.

Installing Maven

First you need to download the latest Maven 2, which currently is Maven-2.0.4, make sure you download the binary archive (maven-2.0.4-bin.zip).

Installing Maven should be easy: unzip the file to any directory you like, let's say:

C:\maven-2.0.4

Next you need to do 2 things:

  • add an environment variable MAVEN_HOME which points to the install directory of Maven, i.e. C:\maven-2.0.4
  • add %MAVEN_HOME%\bin to your path (using the variable you can switch more easily when a new version arrives)

Using Maven

Maven defines several goals, for creating and building your application. A goal is similar to an Ant-task. For instance: to compile the java sources one could do:
mvn compile
Also, a goal can depend on other goals: the package goal depends on running the unit tests and compilation of the code.

See the Maven site for more information on the different goals and plugins that are available.

Building jWebUnit

Building jWebUnit merely consist of running Maven:

mvn package
If you build jWebUnit and you configured Maven as described earlier, you will see the following text:
$ mvn package
[INFO] Scanning for projects...
[INFO] Reactor build order:
[INFO]   jWebUnit
[INFO]   Core - API
[INFO]   Commons Tests
[INFO]   HtmlUnit Plugin
[INFO] ----------------------------------------------------------------------------
[INFO] Building jWebUnit
[INFO]    task-segment: [package]
[INFO] ----------------------------------------------------------------------------
[INFO] [site:attach-descriptor]
[INFO] ----------------------------------------------------------------------------
[INFO] Building Core - API
[INFO]    task-segment: [package]
[INFO] ----------------------------------------------------------------------------
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
Compiling 14 source files to /home/julien/jwebunit-1.x/jwebunit-core/target/classes
[INFO] [resources:testResources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:testCompile]
Compiling 1 source file to /home/julien/jwebunit-1.x/jwebunit-core/target/test-classes
[INFO] [surefire:test]
[INFO] Surefire report directory: /home/julien/jwebunit-1.x/jwebunit-core/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running net.sourceforge.jwebunit.TableTest
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.092 sec

Results :
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0

[INFO] [jar:jar]
[INFO] Building jar: /home/julien/jwebunit-1.x/jwebunit-core/target/jwebunit-core-1.3.jar
[INFO] ----------------------------------------------------------------------------
[INFO] Building Commons Tests
[INFO]    task-segment: [package]
[INFO] ----------------------------------------------------------------------------
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
Compiling 23 source files to /home/julien/jwebunit-1.x/jwebunit-commons-tests/target/classes
[INFO] [resources:testResources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:testCompile]
Compiling 1 source file to /home/julien/jwebunit-1.x/jwebunit-commons-tests/target/test-classes
[INFO] [surefire:test]
[INFO] Surefire report directory: /home/julien/jwebunit-1.x/jwebunit-commons-tests/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running net.sourceforge.jwebunit.tests.util.reflect.MethodInvokerTest
Tests run: 7, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.077 sec

Results :
Tests run: 7, Failures: 0, Errors: 0, Skipped: 0

[INFO] [jar:jar]
[INFO] Building jar: /home/julien/jwebunit-1.x/jwebunit-commons-tests/target/jwebunit-commons-tests-1.3.jar
[INFO] ----------------------------------------------------------------------------
[INFO] Building HtmlUnit Plugin
[INFO]    task-segment: [package]
[INFO] ----------------------------------------------------------------------------
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
Compiling 1 source file to /home/julien/jwebunit-1.x/jwebunit-htmlunit-plugin/target/classes
[INFO] [resources:testResources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:testCompile]
Compiling 1 source file to /home/julien/jwebunit-1.x/jwebunit-htmlunit-plugin/target/test-classes
[INFO] [surefire:test]
[INFO] Surefire report directory: /home/julien/jwebunit-1.x/jwebunit-htmlunit-plugin/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running net.sourceforge.jwebunit.htmlunit.JWebUnitTest
:INFO:  Logging to STDERR via org.mortbay.log.StdErrLog
:INFO:  jetty 6.0.0beta16
:INFO:  Extract jar:file:/home/julien/jwebunit-1.x/jwebunit-commons-tests/target/jwebunit-commons-tests-1.3.jar!/testcases/ to /tmp/Jetty__jwebunit/webapp
:INFO:  NO JSP Support for /jwebunit, did not find org.apache.jasper.servlet.JspServlet
:INFO:  Started SocketConnector @ 0.0.0.0:8082
Tests run: 162, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 7.877 sec

Results :
Tests run: 162, Failures: 0, Errors: 0, Skipped: 0

[INFO] [jar:jar]
[INFO] Building jar: /home/julien/jwebunit-1.x/jwebunit-htmlunit-plugin/target/jwebunit-htmlunit-plugin-1.3.jar
[INFO]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] ------------------------------------------------------------------------
[INFO] jWebUnit .............................................. SUCCESS [2.922s]
[INFO] Core - API ............................................ SUCCESS [5.128s]
[INFO] Commons Tests ......................................... SUCCESS [3.416s]
[INFO] HtmlUnit Plugin ....................................... SUCCESS [12.735s]
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 24 seconds
[INFO] Finished at: Fri Jul 28 20:28:48 CEST 2006
[INFO] Final Memory: 8M/19M
[INFO] ------------------------------------------------------------------------

You now have successfully built jWebUnit 1.3. The files are in target/ folder.