Green Beans: Getting Started with Maven and Spring

Engineering | Josh Long | January 17, 2011 | ...

Apache Maven is a popular open source tool that offers a convention-over-configuration approach to project build management. Indeed the Eclipse Community Surveys show Maven increased its adoption from 8% in 2009 to 28% in 2010, underscoring its usefulness in a wide range of project settings. Even though you can use Spring without using Maven, there are many reasons to recommend its use to Spring developers. In this post I'll show you how to get started using Maven, and how to use it successfully with Spring libraries, repositories and tooling like SpringSource Tool Suite and Spring Roo.

Maven handles project builds. Maven can provide a lot of power and sophistication with relative ease if your project follows Maven's conventions. It is declarative; you describe what you want done, not how you want it done. This approach will seem different if you've come from venerable build tools like Make, or Ant.

You declare your project's dependencies in the Maven project configuration. These dependencies are then resolved on your behalf and downloaded for you. This is similar to the package system found in many different operating systems. Suppose you're using OS X's fink or ports command line tools. To update an operating system's a functionality, a user selects a package (say, the latest security patches, or a new version of the glib library) to install in an administration client and then instruct the client to downloaded and install it from well-known servers, referred to as package repositories. When the package is downloaded, the package manager consults the package's manifest which enumerates all the libraries (found in other packages) that the package depends on - its transitive dependencies. Those too are downloaded.

There are several ways to install Maven If you haven't already got it installed. Download it from the Apache web site. Choose a more recent version. Currently, many people are using Maven 2.21, or the recently released Maven 3. Download the version you'd like to use and then unzip it to a directory of your choice. Alternatively, several operating systems provide Maven 2 builds (and soon, Maven 3 builds) in the package system. For example, on Ubuntu, you can run sudo apt-get install maven2 . If you're using the SpringSource Tool Suite (available here for download for free), then you don't need to worry, Maven's already downloaded and included in your STS installation folder. Regardless of how you get the Maven binaries on your system, ensure that the binary is on your operating system's search path. Usually, this is just a matter of adding the Maven installation's bin folder to your operating system's PATH variable. It's also a good practice to create a system variable for the Maven installation itself, called MAVEN_HOME. On a Unix (including OS X) or Linux machine, this setup looks about the same. On my machine (an Ubuntu Linux machine), it looks like this:

export MAVEN_HOME=/home/jlong/bin/springsource/maven-2.2.1.RELEASE 
export PATH=$PATH:$MAVEN_HOME/bin

To test it, open up a new shell and issue the following command:

mvn --version

You should see some output confirming the command presence on your system, like this:


jlong@jlong-mbp:~/Desktop/code$ mvn --version 
Apache Maven 2.2.1 (r801777; 2009-08-06 12:16:01-0700) 
Java version: 1.6.0_22 
Java home: /usr/lib/jvm/java-6-sun-1.6.0.22/jre 
Default locale: en_US, platform encoding: UTF-8 
OS name: "linux" version: "2.6.35-22-generic" arch: "amd64" Family: "unix" 
jlong@jlong-mbp:~/Desktop/code$ 

Getting Started With Maven

Maven projects assume a standard directory structure, which looks - at a minimum - like this:

./pom.xml ./src ./src/main ./src/main/java ./src/main/resources ./src/test ./src/test/java ./src/test/resources

At the root of the directory structure is a XML file (always called pom.xml) that Maven expects. The pom.xml (POM is short for Project Object Model) describes the things specific to your project that can't be inferred automatically like dependencies, the name of the project, etc.

Directory Description Directory's Contents (relative to the project root)
src/main/java Contains the Java source code for your project
src/main/resources Contains any classpath-relative resources for your project (like, a Spring application context .xml file)
src/test/java Contains the java source code for your test…

What's New In Spring Roo 1.1.1

Engineering | Ben Alex | January 11, 2011 | ...

It's our pleasure to announce the general availability of Spring Roo 1.1.1. This new release incorporates over 250 fixes and enhancements, including many performance and functionality improvements.

As always, SpringSource Tool Suite (STS) 2.5.2 will be released very shortly and incorporate this new version of Spring Roo. You can also download the standalone version of Spring Roo 1.1.1 and get started immediately.

Let's briefly tour some of the more notable enhancements we're added to Roo 1.1.1. If you're upgrading your Roo-based projects, we encourage you to review the version-specific upgrade notes we include in the reference guide. The reference guide is also included in the…

Spring Web Services 2.0 Released

Engineering | Arjen Poutsma | January 11, 2011 | ...

After being in the works for almost a year, I'm happy to announce that Spring Web Services 2.0 has been released! In this post, I'd like to go over some of the major new features.

Java 5+ and Spring 3.0 Required

As you are probably aware, we moved the Object XML Mapping (OXM) module from the Spring-WS project into Spring 3.0. As such, it was a bit problematic to use Spring-WS 1.5 (with its own OXM module) with Spring 3.0, due to conflicting classes in the org.springframework.oxm package.

As of version 2.0, we no longer ship the OXM module as part of Spring-WS, but depend on Spring's OXM instead. As a result, Spring Web Services 2.0 requires Spring 3.0 to work. Normally, we tend to be a bit more lenient with regard to version requirements, not necessarily requiring the latest Spring version, but this was the…

SpringSource Tool Suite 2.5.2 Released

Releases | Christian Dupuis | January 11, 2011 | ...

Dear Spring Community

I'm pleased to announce that we just released SpringSource Tool Suite (STS) 2.5.2.RELEASE.

Some highlights from the new release:

  • Support for Spring Roo 1.1.1.RELEASE
  • Easy creation of new tc Server instances
  • Improved graphical Spring Web Flow editor
  • Agent-based reloading (experimental)
  • A large number of improvements to the Spring and Groovy/Grails tooling
  • Integration of Spring User Agent Analysis (UAA)

More details on new features and bug fixes can be found in the New and Noteworthy document. Detailed installation instructions are also available.

As always downloads are available from the STS Download page. Feel free to stop by the community support forum if you have any question or issue.

Green Beans: Getting Started with Spring in your Service Tier

Engineering | Josh Long | January 08, 2011 | ...

All applications stem from a domain model. The term "domain model" describes the nouns, or data, in a system that is important to the problem you're trying to solve. The service tier - where business logic lives - manipulates the application data and must ultimately persist it (typically, in a database). The explanation is simple, but in practice building a good service tier can be a daunting task for any developer. This post will introduce developers to the options available in the Spring framework for building a better service tier. It is assumed that the reader has some experience with the…

Green Beans: Getting Started with Spring MVC

Engineering | Colin Sampaleanu | January 04, 2011 | ...

Spring MVC, a part of the core Spring Framework, is a mature and capable action-response style web framework, with a wide range of capabilities and options aimed at handling a variety of UI-focused and non-UI-focused web tier use cases. All this can potentially be overwhelming to the Spring MVC neophyte. I think it's useful for this audience to show just how little work there is to get a bare Spring MVC application up and running (i.e. consider my example something akin to the world's simplest Spring MVC application), and that's what I'll spend the rest of this article demonstrating.

I'm assuming you are familiar with Java, Spring (basic dependency injection concepts), and the basic Servlet programming model, but do not know Spring MVC. After reading this blog entry, readers may continue learning about Spring MVC by looking at Keith Donald's Spring MVC 3 Showcase

Spring Web Services 2.0.0.RC2 Released

Releases | Adam Fitzgerald | December 23, 2010 | ...

Dear Spring community,

We are pleased to announce that Spring Web Services 2.0 Release Candidate 2 has been released!

This is the second release candidate in the 2.0 release cycle. The most important new feature in this release is the update of the Spring-WS XML namespace, which now contains <sws:annotation-driven/> and <sws:interceptors/> elements (similar to the Spring-MVC namespace), and <sws:static-wsdl/> and <sws:dynamic-wsdl/> for exporting your WSDLs. All of these features are described in the updated reference documentation.

We consider this release (RC2) complete. If no major new issues are found, we will release 2.0.0-RELEASE in the first half of January 2011.

While we did make some changes, Spring-WS 2.0 should be a drop-in replacement for 1.5 with just one exception. Please read the forum post for the details.

Download | Documentation | ChangeLog | Community Forum

Spring GemFire 1.0.0.RC1 Released for Java and .NET

Releases | Costin Leau | December 21, 2010 | ...

Dear Spring Community,

We are pleased to announce the first release candidate of the Spring GemFire 1.0 project is now available for both Java and .NET! The Spring GemFire project aims to make it easier to build Spring-powered highly scalable applications using GemFire as distributed data management platform.

The RC updates include:

  • Upgrades to the latest Spring, Spring.NET and Gemfire releases
  • Documentation improvements

To learn more about the project, visit the Spring GemFire homepage.

Download it now: Spring GemFire for Java | Spring GemFire for .NET

We look forward to your feedback!

Git and Social Coding: How to Merge Without Fear

Engineering | Dave Syer | December 21, 2010 | ...

Git is great for social coding and community contributions to open source projects: contributors can try out the code easily, and there can be hordes of people all forking and experimenting with it but without endangering existing users. This article presents some examples with the Git command line that might help build your confidence with this process: how to fetch, pull and merge, and how to back out of mistakes. If you are interested in the social coding process itself, and how to contribute to Spring projects, check out another blog on this site by Keith Donald.

Grails has been on Github for a while and had a great experience with community contributions, so some other projects from SpringSource are starting to migrate over there as well. Some of the migrating projects are new (e.g. Spring AMQP) and some are already established and have migrated from SVN (e.g. Spring Batch). There are also some Spring projects on a SpringSource hosted Gitorious instance, for example Spring Integration

Get the Spring newsletter

Stay connected with the Spring newsletter

Subscribe

Get ahead

VMware offers training and certification to turbo-charge your progress.

Learn more

Get support

Tanzu Spring offers support and binaries for OpenJDK™, Spring, and Apache Tomcat® in one simple subscription.

Learn more

Upcoming events

Check out all the upcoming events in the Spring community.

View all