Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to create spring project with maven

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

like image 437
Gandalf StormCrow Avatar asked Mar 18 '10 15:03

Gandalf StormCrow


2 Answers

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.

like image 155
Pascal Thivent Avatar answered Oct 10 '22 09:10

Pascal Thivent


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.

like image 24
matt b Avatar answered Oct 10 '22 09:10

matt b