Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create Spring web project with Maven in Eclipse?

I tried to make project by selecting Archtype Web Application from Eclipse create new maven project. But when I created a new java Class to project sources folder, it didn't contain packacge name in package and source folder was included in class path. So is there something wrong with my setup or why doesn't Eclipse add automatically package to newly created Class?

like image 826
newbie Avatar asked Jun 20 '10 06:06

newbie


People also ask

How do I run a Maven webapp project in Eclipse?

To run the maven project, select it and go to “Run As > Java Application”. In the next window, select the main class to execute. In this case, select the App class and click on the Ok button. You will see the “Hello World” output in the Console window.


3 Answers

This is what I do:

  • Using m2eclipse plugin for Maven integration and m2eclipse WTP integration (from m2eclipse extras update site).
  • Create new maven project using archetype: maven-archetype-webapp.
  • Create src/main/java folder and add to build path manually.
  • Add spring and spring-webmvc dependencies. For 2.5.6.SEC01 version use:
<dependency>   <groupId>org.springframework</groupId>   <artifactId>spring</artifactId>   <version>2.5.6.SEC01</version> </dependency> <dependency>   <groupId>org.springframework</groupId>   <artifactId>spring-webmvc</artifactId>   <version>2.5.6.SEC01</version> </dependency> 
  • Develop a Spring MVC application step by step.
like image 139
sourcerebels Avatar answered Nov 14 '22 02:11

sourcerebels


The easiest way would to use Spring Tool Suite as suggested by @Stephen which is a bundled version of Eclipse for Spring development. It packages plugins such as Spring IDE, M2Eclipse, etc and offers custom Project templates for Spring projects (via New > Project...). This gives you a fully configured project.

The Maven webapp archetype allows to obtain a similar result but involves more manual steps: you'll have to add src/main/java, create the base package and add Spring dependencies manually (so no, there is nothing particularly wrong with you setup).

like image 27
Pascal Thivent Avatar answered Nov 14 '22 02:11

Pascal Thivent


In Spring Tool Suite (STS) you can try this. Create a Maven project. You can add pom.xml dependencies to whatever Spring libs you may need. For example:

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-core</artifactId>
  <version>3.0.5.RELEASE</version>
  <type>pom</type>
  <scope>compile</scope>
</dependency>

After the project is created, right click it in the Package Explorer and choose Spring Tools -> Add Spring Project Nature. Et voila, you should have a Maven/Spring project.

like image 29
Rob Avatar answered Nov 14 '22 04:11

Rob