views:

416

answers:

4

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?

A: 

From the new project creation man page:

It then asks you to enter the values for the groupId, the artifactId and the version of the project to create and the base package for the sources.

[INFO] artifact org.apache.maven.archetypes:maven-archetype-quickstart: checking for updates from maven-archetype-quickstart-repo
Downloading: http://repo1.maven.org/maven2/org/apache/maven/archetypes/maven-archetype-quickstart/1.0/maven-archetype-quickstart-1.0.jar
4K downloaded
Define value for groupId: : com.company 
Define value for artifactId: : project
Define value for version: : 1.0
Define value for package: : com.company.project
Confirm properties configuration:
groupId: com.company
artifactId: project
version: 1.0
package: com.company.project
 Y: : 

If the base package is set, a newly created class should be under that package.
Does the source folder contains an empty 'com.company.project' package?

VonC
+1  A: 

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>
SourceRebels
More details than in my answer. +1
VonC
A: 

The SpringSource guys have developed an Eclipse-based Spring Tool Suite for developing Spring projects. I've never used STS ... but if you are starting a new project, this might be a good time to give it a spin.

Stephen C
+1  A: 

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).

Pascal Thivent