While an IDE importer can sometimes be convenient, there is no need to turn a project in Eclipse into a maven project. Basically, you just need to add the pom.xml file and follow the maven rules - or configure it.
Using maven-eclipse-plugin , it is actually possible that maven itself generates the necessary files to integrate your maven project with eclipse:
- Start from command line
- Go to the root of the project
- Create a new
pom.xml file from a simple template or create a new project folder structure (including pom) using mvn archetype:generate - Type
mvn eclipse:eclipse .
Then maven generated the necessary files for integration with eclipse.
However, maven by convention expects a certain folder structure for your Java project. It looks like this:
my-app |-- pom.xml `-- src |-- main | `-- java | `-- com | `-- mycompany | `-- app | `-- App.java `-- test `-- java `-- com `-- mycompany `-- app `-- AppTest.java
So, if you don't already have this structure, you need to move the source code to main / java (and unit test code to test / java).
In addition, if your project has dependencies for other projects; then you need to express these dependencies in the Maven pom.xml file. If your dependency projects are stored in Maven Central, this is especially easy. To express a dependency, for example, Apache Commons - you would add this to your pom.xml:
<project> ... <dependencies> ... <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-io</artifactId> <version>1.3.2</version> </dependency> ... </dependencies> ... </project>
After these initial attempts to integrate your project with maven, you can try building using mvn compile from the command line or using m2eclipse for Eclipse.
source share