Home > Articles > Programming > Java

  • Print
  • + Share This
From the author of

Introducing Maven

Maven is a powerful project build tool. Some people see it as a replacement for Ant. Perhaps the central idea of Maven is the notion of a repository—the area (or folder) into which all built artifacts can be placed. Another important Maven concept is that of the project object model (POM), which is used for building artifacts. There's a lot of information about Maven on the Web, so let's take a look at Maven in action.

Open a DOS console to the folder in which you installed Spring web services. For example, here's the setup on my system:

cd c:\java\springws\spring-ws-1.5.0\samples\tutorial

Then run the following command:

mvn package

If all is well with your installation, a new folder called target will appear in the current directory. You should also see program output similar to that illustrated in Listing 1.

Listing 1 Maven output.

C:\java\springws\spring-ws-1.5.0\samples\tutorial>mvn package
[INFO] Scanning for projects...
[INFO] -----------------------------------------------------------------------
[INFO] Building Spring WS Holiday Service Tutorial
[INFO]  task-segment: [package]
[INFO] -----------------------------------------------------------------------
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] Compiling 3 source files to C:\java\springws\spring-ws-1.5.0\samples\tutorial\target\classes
[INFO] [resources:testResources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:testCompile]
[INFO] Compiling 1 source file to C:\java\springws\spring-ws-1.5.0\samples\tutorial\target\test-classes
[INFO] [surefire:test]
[INFO] Surefire report directory: C:\java\springws\spring-ws-1.5.0\samples\tutorial\target\surefire-reports
-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.mycompany.hr.ws.HolidayEndpointTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.64 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] [war:war]
[INFO] Packaging webapp
[INFO] Assembling webapp[tutorial] in [C:\java\springws\spring-ws-1.5.0\samples\tutorial\target\tutorial-1.5.0]
[INFO] Processing war project
[INFO] Webapp assembled in[7688 msecs]
[INFO] Building war: C:\java\springws\spring-ws-1.5.0\samples\tutorial\target\tutorial.war
[INFO] -----------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] -----------------------------------------------------------------------
[INFO] Total time: 39 seconds
[INFO] Finished at: Sat May 24 12:00:39 BST 2008
[INFO] Final Memory: 8M/19M
[INFO] -----------------------------------------------------------------------

There's a lot of content in Listing 1 for one simple command (mvn package)! Let's have a quick look. The first part of the output starts the build of the web service. The next part runs some unit tests, and the last part builds the WAR file. If you don't know what a WAR file is, think of it as the executable container for the web service. In other words, a WAR file is basically a JAR file that contains the resources needed to deploy and run the web service.

In fact, Listing 1 covers a great deal of ground, and what's going on in the background is worthy of study. Let's turn to the web service we've just built.

  • + Share This
  • 🔖 Save To Your Account