user962206
user962206

Reputation: 16147

Maven Generated Project looks different when importing to Eclipse

I was trying to generate a Simple Spring-MVC project using this this tutorial

However. upon importing the project in eclipse. there were several errors(well for me atleast)

First is this.

The packages are colored white. what I was expecting is the packages should be brown, like the normal projects in Eclipse.

enter image description here

Next. When Implemented the interface Named IndexController. it told me this error

"The Resource is not on the build path of a Java Project

what have I done wrong?

Upvotes: 0

Views: 378

Answers (1)

acdcjunior
acdcjunior

Reputation: 135802

Your .java files are in the resources folder. They should be at a /java/ one.

The workaround is shown below, but first, understand what's going on:

In the Maven default folder structure, Java source files (.java) should be in the /src/*/java folders, such as /src/main/java and /src/test/java.

The /src/*/resources folders are reserved for resources to be used by the program, like configuration/properties files, images and so on:

src
|--main
|  |--java
|  |  |--com
|  |  |  |--mypackage
|  |  |     |--MyClassA.java
|  |  |     |--submypackage
|  |  |        |--SomeOtherClass.java
|  |  |--net
|  |     |--netpackage
|  |        |--MyNetClassA.java
|  |--resources
|     |--myAppConfig.xml
|--test
   |--java
   |  |--com
   |     |--anotherpackage
   |        |--AnotherClassTest.java
   |--resources

How to fix it:

Create a /java/ source folder and place your .java files there:

  • Right-click on Java Resources
  • Select New
  • Select Source Folder
  • Select your project and give the folder the name src/main/java:

creating source folder

The src/main/java should be created. Move the packages (the com.todolist.* items) with the .java files there.

If you can, just to make sure Maven/Eclipse catches up to the new structure: right-click your project and click Maven -> Update Project...:

maven update project

Upvotes: 1

Related Questions