Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change Eclipse project folder structure to Maven/Gradle structure

I have created a Java project using Eclipse. Since I didn't do anything special, its folder structure is the default one that all Eclipse projects use:

Project
└── src
    ├── foo
    │   └── MyClass.java
    └── fooTests
         └── MyTest.java

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

Project
└── src
    ├── main
    │   └── foo
    │       └── MyClass.java
    └── test
        └── foo
            └── MyTest.java

However, there doesn't seem to be an obvious way to change my folder structure. The big issue seems to be what to do with the source folder. I tried to do this manually, but it tried to make the package for MyClass.java as main.foo, which I obviously don't want. I haven't found a maven or gradle plugin that converts the structure automatically.

How do I go about changing my Eclipse project folder structure to a Maven/Gradle structure?

like image 847
Thunderforge Avatar asked Jul 15 '15 03:07

Thunderforge


People also ask

Is a Maven project comes with a specific folder structure?

Maven project structure defines a folder in order to store all resources and files needed by a web application. Inside this folder you can put all the required files for a web application like jsp files, js files, html files, css files, template files, reports files, WEB-INF files (like web. xml), META-INF files, etc…

What is project structure in Eclipse?

Whenever you make a project inside of Eclipse, Eclipse will auto-magically create a new folder in your workspace with the same name. Inside of that folder it will create two folders: bin, and src (source). The bin folder can be ignored. This is nothing more than the folder in which Eclipse stores the .


1 Answers

You can actually do all of this manually with minimal fuss.

  1. In the Package Explorer view, right-click on your src folder and choose "Build Path" -> "Remove from Build Path"
  2. Underneath the src folder, create a main/java folder
  3. Right-click on the main/java folder and choose "Build Path" -> "Use as Source Folder"
  4. Repeat steps 2 and 3 for test/java
  5. Using the Eclipse refactoring tools (right-click on a folder or file and choose "Refactor" -> "Move…", move your Java files to the new folders

Once you're done with the refactoring, your project will be structured in the Maven way. This will make things much simpler when you decide to actually start using Gradle and Maven for your project.

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

like image 115
Thunderforge Avatar answered Sep 17 '22 13:09

Thunderforge