Maven Integration with Existing Java Project Using Eclipse

I created this Java project using struts, hibernate in Eclipse Helios,

Now I want to integrate this project with Maven, how to do it?

I have already installed Maven In Eclipse.

The tutorials, blogs, sites that I have found so far explain the integration of a project in Maven outside of Eclipse, and then import it into Eclipse or create a new project with Maven. Some of them still solve my problem.

As I said, I already created a project in Eclipse. Now I just want to integrate it with Maven, how to do it?

+6
source share
2 answers

In eclipse, you can easily convert a java project to maven by right clicking on the project -> configure -> convert to maven project.

+8
source

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.

+5
source

Source: https://habr.com/ru/post/947458/


All Articles