views:

274

answers:

4

Hello everyone I was just going trough http://static.springsource.org/docs/Spring-MVC-step-by-step/part1.html spring tutorial, and I thought its old I'll think something better on my own. For starters how do I start spring project with maven, which archtype should I choose? I wanna create simple spring app, write class which I will deploy to jboss, spring will instansiate it at startup .. that is what have in mind for now .. for now I need to start it first

+2  A: 

An archetype only sets up your POM and directory structure based on a template. I wouldn't get hung up on which one to choose.

The MVC tutorial uses the following structure:

  • src - Java source code
  • war - Web resources, web.xml, and Spring context files

If you want to use the Maven standards, this should convert to

  • src/main/java - Java source code
  • src/main/resources - Spring context files and configuration (non-web related) files, which you'd like to be on the classpath (i.e. WEB-INF/classes) in a webapp
  • src/main/webapp - Web-related resources which you'd like to appear at the root of your webapp/.war file

And the <packaging> for a webapp should be war.

Update: I'd recommend taking a look at the free Maven by Example book, it walks you through building a sample application using Maven, including a chapter on "A Simple Web Application". There is also Maven: The Complete Reference for more reference.

matt b
+4  A: 

The Spring 3 samples are maven based and are a good starting point. Just get them from their source control: https://src.springframework.org/svn/spring-samples/

Another option would be to use an AppFuse archetype like the appfuse-modular-spring to create a modular application with Hibernate, Spring and Spring MVC.

Pascal Thivent
+1  A: 

appfuse has a maven archetype for creating webapp with spring, hibernate and spring MVC

artifactId: appfuse-basic-spring groupId: org.appfuse.archetypes

Stefan De Boey
A: 

You can create a project using the web archetype:

mvn archetype:create -DgroupId=com.mycompany.app -DartifactId=my-webapp -DarchetypeArtifactId=maven-archetype-webapp

Then add spring as a dependency in the generated pom.xml to get the spring jars:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring</artifactId>
    <version>2.5.6</version>
</dependency>

You can follow the spring tutorials from there.

You will need to update the java source version to 1.5 in the pom for annotations etc, it describes how to do this on the maven site.

Neal Donnan