For a project at work, we're considering using the Maven plugin for Eclipse to automate our builds. Right now the procedure is far more complicated than it ought to be, and we're hoping that Maven will simplify things to a one-click build.
My question is, is there a wizard or automatic importer for converting an existing Eclipse Java project to a Maven project, using the Maven plugin? Or should I create a new Maven project and manually copy over all source files, libs, etc.
Right click on the Project name > Configure > Convert to Maven Project > click finish. Here you will add some dependencies to download and add your expected jar file.
This will create an auto-generated pom.xml file. Open that file in xml format in your eclipse editor. After build tag (
</build>
) add your dependencies which you can copy from maven website and add them there. Now you are good to go. These dependencies will automatically add your required jar files.If you just want to create a default POM and enable m2eclipse features: so I'm assuming you do not currently have an alternative automated build setup you're trying to import, and I'm assuming you're talking about the m2eclipse plugin.
The m2eclipse plugin provides a right-click option on a project to add this default pom.xml:
Newer M2E versions
Right click on Project -> submenu Configure -> Convert to Maven Project
Older M2E versions
Right click on Project -> submenu Maven -> Enable Dependency Management.
That'll do the necessary to enable the plugin for that project.
To answer 'is there an automatic importer or wizard?': not that I know of. Using the option above will allow you to enable the m2eclipse plugin for your existing project avoiding the manual copying. You will still need to actually set up the dependencies and other stuff you need to build yourself.
For converting to Gradle is analogue to Maven:
Right click on Project -> submenu Configure -> Convert to Gradle (STS) Project
It's necessary because, more or less, when we import a project from git, it's not a maven project, so the maven dependencies are not in the build path.
Here's what I have done to turn a general project to a maven project.
general project-->java project right click the project, properties->project facets, click "java". This step will turn a general project into java project.
java project --> maven project right click project, configure-->convert to maven project At this moment, maven dependencies lib are still not in the build path. project properties, build path, add library, add maven dependencies lib
And wait a few seconds, when the dependencies are loaded, the project is ready!
I was having the same issue and wanted to Mavenise entire eclipse workspace containing around 60 Eclipse projects. Doing so manually required a lot of time and alternate options were not that viable. To solve the issue I finally created a project called eclipse-to-maven on github. As eclipse doesn't have all necessary information about the dependencies, it does the following:
Based on
<classpathentry/>
XML elements in .classpath file, it creates the dependencies on another project, identifies the library jar file and based on its name (for instance jakarta-oro-2.0.8.jar) identifies its version. CurrentlyartifactId
andgroupId
are same as I couldn't find something which could return me the Maven groupId of the dependency based onartifactId
. Though this is not a perfect solution it provides a good ground to speed up Mavenisation.It moves all source folders according to Maven convention (like
src/main/java
)As Eclipse projects having names with spaces are difficult to deal on Linux/Unix environment, it renames them as well with names without spaces.
Resultant pom.xml files contain the dependencies and basic pom structure. You have to add required Maven plugins manually.
As far as I know, there is nothing that will automagically convert an Eclipse project into a Maven project (i.e. modify the layout, create a POM, "generate" and feed it with metadata, detect libraries and their versions to add them to the POM, etc). Eclipse just doesn't have enough metadata to make this possible (this is precisely the point of the POM) and/or to produce a decent result.
That would be the best option in my opinion. Create a Maven project, copy/move sources, resources, tests, test resources into their respective directories, declare dependencies, etc.