4

I have created a project using the following maven webapp project in eclipse:

enter image description here

When adding a package to the project (right click project -> new -> package), the package gets added as a folder (I added a package named core). It does not have the usual package icon:

enter image description here

If I try to create a new class and select a package, there are no entries in the list box. I have tried creating packages in a normal eclipse dynamic web project and these work correctly.

How do I get packages in Maven enabled webapp projects?

cardori
  • 235
  • 1
  • 5
  • 13

3 Answers3

16

Your code should be in src/main/java. If it doesn't exist already, create it, and then pick Maven -> Update Project from the context menu on the project.

You'll then see src/main/java alongside src/main/resources. Right click that, select New -> Package, and it should appear as you'd expect.

Maven won't compile sources under src/main/resources, which is why your code needs to be in src/main/java. The src/main/resources directory is for files that you want to appear on your classpath, which don't need to be compiled. You might put properties files there, for example.

Edit: The reason that 'resources' folders aren't shown in the usual layout in Package Explorer is that m2e sets up resource folders in a different way to source folders. For an explanation of why it does that, see: Maven/Eclipse: The default build path for resources excluded everything

Community
  • 1
  • 1
Martin Ellis
  • 9,603
  • 42
  • 53
  • 1
    Thanks, got everything working now. I am new to Maven and still getting used to its idiosyncrasies :) – cardori Oct 18 '12 at 17:46
2

I have solved this issue by below steps:

  1. Right click the Maven Project -> Build Path -> Configure Build Path
  2. In Order and Export tab, you can see the message like '2 build path entries are missing'
  3. Now select 'JRE System Library' and 'Maven Dependencies' checkbox
  4. Click OK

Now you can see below in all type of Explorers (Package or Project or Navigator)

src/main/java
src/main/resources
src/test/java
src/main/webapp
Viks
  • 1,041
  • 1
  • 9
  • 15
0

If some is still facing issue here is solution which worked for me

right click on project -> build path -> configure build path -> order & export -> check JRE system libraries 1.5 and maven dependancy