Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't create packages with Maven webapp

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?

like image 821
cardori Avatar asked Dec 04 '22 01:12

cardori


2 Answers

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

like image 53
Martin Ellis Avatar answered Dec 21 '22 12:12

Martin Ellis


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
like image 45
Viks Avatar answered Dec 21 '22 13:12

Viks