How to change the folder structure of an Eclipse project to a Maven / Gradle structure

I created a Java project using Eclipse. Since I did not do anything special, its folder structure is the default default that all Eclipse projects use:

Project -src -foo -MyClass.java -fooTests -MyTest.java 

However, I would like to transfer this to the folder structure used by Maven and derivatives like Gradle.

 Project -src -main -foo -MyClass.java -test -foo -MyTest.java 

However, there seems to be no obvious way to change the folder structure. The big problem seems to be what to do with the source folder. I tried to do this manually, but tried to make a package for MyClass.java as main.foo , which I obviously don't want. I did not find a maven or gradle plugin that automatically converts the structure.

How do I change the folder structure of an Eclipse project to a Maven / Gradle structure?

+5
source share
2 answers

You can do it all manually with minimal noise.

  • In the Package Explorer view, right-click the src folder and select Build Path β†’ Remove from Build Path.
  • Under the src folder, create the main/java folder
  • Right-click the main/java folder and select "Build Path" β†’ "Use as Source Folder"
  • Repeat steps 2 and 3 for test/java
  • Using the Eclipse refactoring tools (right-click on a folder or file and select "Refactoring" β†’ "Move ...", move your Java files to new folders.

As soon as you finish the refactoring, your project will be structured according to the Maven principle. This will greatly simplify the work when you decide to start using Gradle and Maven for your project.

Please note that Java will still display your src/main folder separately in the project viewer. This is normal. Eclipse shows the source folder at the top, and then all the other folders in the project view, which include the parents of the source folder.

+5
source

Eclipse does this for you if you have maven and gradle installed. Right-click the name of the project, get to the end of the list, select configure and it will have 2 options, 1 - to convert to a maven project and 1 to convert to a gradle project. It handles the source reset, etc.

0
source

All Articles