Converting Eclipse Projects to Maven : eclipse-to-maven Intro

Converting a single Eclipse project to Maven is a small task but it becomes huge when you have to deal with hundreds of Eclipse projects. Again this is common in large enterprises. In this context, it can be very useful to have a tool which does just that. The eclipse-to-maven project on github has been created for this purpose.

In current shape it has following features:

  • Converts .classpath files into pom.xml.
  • Moves source folders according to Maven convention. For instance Java sources go to src/main/java folder.
  • Removes spaces in the names of the folders, e.g. “Calculator Component” becomes “CalculatorComponent”.
  • Right now Mavenisation is limited to generating dependencies in the pom. However this is a great first step in pom generation. With small changes you can run the Maven build for your projects.

Though software world has already moved on with latest technology developments, many projects in big enterprises are still running on old technologies. In large enterprises technology selection and change is still a big issue just because it comes with a cost of maintaining hundreds of software applications. If they don’t select and limit technologies properly, they can be in big complex soup.

Changing technologies swiftly can be one extreme and another extreme can be not changing anything at all. This eventually may mean huge time taken in introducing any new feature in legacy software. Maintenance also becomes big headache. So though it’s okay doing technology selection properly, it’s important also to adapt with changing environment and continuously ensuring the quality improvement.

In current context, I am talking about Maven-ising the existing Eclipse workspace. Maven is important step in build automation and is a high level build language compared to Ant. Adding new quality features in Maven is just a matter of few line changes.

Maven is convention based build approach where project structure is consistent across. So instead of looking for new source folders and adapting the build script accordingly, Maven knows the default project structure which is all it needs.

Eclipse workspace can have various issues such as:

  • No specific source folders. Any folder can be a source folder which forces build scripts to adapt accordingly. In long run it’s a huge waste
  • Eclipse projects having names containing spaces for instance “Calculator Component”. It can be very difficult to work with these folders in Linux/Unix environments.
  • No consistency in having test-cases and their specific folders in the projects
  • No difference between test-cases related dependency and main build dependencies. So all jars eventually become part of the end product (war or ear file).

Let’s see how much Maven-ising existing Eclipse projects to Maven is useful.

  • Maven works on the “Convention Over Configuration” concept in which systems, libraries, and frameworks should assume reasonable defaults. Without requiring unnecessary configuration, systems should “just work”.
  • As you don’t have to worry about configuration anymore, you can focus your energies in doing the actual real stuff which again doesn’t remain a big deal
  • Maven comes with a lot of plugins. Instead of creating things from the scratch, you can be rest assured as majority of the requirements have already been implemented as Maven plugins and all you have to do is to just write few lines of XML in your pom and you are done.
  • When it comes to using plugins, there are many plugins available which help a lot in quality improvements and assessing the existing code quality. The plugins like cobertura, surefire (comes as default), sonar, checkstyle and PMD are invaluable. These quality tools can be integrated with Continuous Integration tools. So for instance your code coverage drops below a threshold (e.g. 75%), the build will break and notification will be sent to the team.
  • Not to mention build becomes single click

ShriKant Vashishtha is an enterprise Agile Coach, IT strategist, trainer, thinker and hands-on geek. He is passionate towards enterprise Agile transformation, quality aspect of software development including TDD, refactoring, Continuous Delivery, DevOps and Test Automation. He can be reached at vashishtha_sk@yahoo.com.

Posted in Eclipse, eclipse-to-maven, Maven
3 comments on “Converting Eclipse Projects to Maven : eclipse-to-maven Intro
  1. Kaushal says:

    Hi,
    Very nice idea, I liked it. I took this project from github and found a couple of possible improvement
    1. SrcClasspathEntryProcessor.moveSourcesToMavenFolders – We can improve this method by providing support for other mave standard structure like “src/test/resources”, “src/main/resources” etc.
    2. EclipseToMavenFoldersMover.moveSources – Here we might have to do nothing if source and destination matches. For example, if someone executes this utility for a project(s) where few are already mavenized and few are not.
    3. It would be very nice if somehow a assembly project is created which builds the entire project (s).

    I have send you the changes for 1 and 2 in email. Please check it, if it makes sense then do update the code

    Once again….nice thought…good work

    Regards,
    Kaushal

  2. Manta Durai says:

    Nice idea!
    We are rocky in this field and after following all steps get something like this on running eclipse-to-maven from eclipse:
    Any idea?
    =========================================
    Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/commons/configuration/ConfigurationException
    at com.shri.eclipsetomaven.pom.BasicPomStructure.addGroupId(BasicPomStructure.java:58)
    at com.shri.eclipsetomaven.pom.BasicPomStructure.addDefaultElementsToProjectElement(BasicPomStructure.java:48)
    at com.shri.eclipsetomaven.pom.BasicPomStructure.createBasicPomStructure(BasicPomStructure.java:32)
    at com.shri.eclipsetomaven.pom.ClasspathToPomConverter.createPomDoc(ClasspathToPomConverter.java:47)
    at com.shri.eclipsetomaven.WorkspaceClasspathToPomConverter.createPomXmlDoc(WorkspaceClasspathToPomConverter.java:82)
    at com.shri.eclipsetomaven.WorkspaceClasspathToPomConverter.convert(WorkspaceClasspathToPomConverter.java:34)
    at com.shri.eclipsetomaven.WorkspaceClasspathToPomConverter.convertInSubFolders(WorkspaceClasspathToPomConverter.java:94)
    at com.shri.eclipsetomaven.WorkspaceClasspathToPomConverter.convert(WorkspaceClasspathToPomConverter.java:32)
    at com.shri.eclipsetomaven.EclipseToMaven.maveniseTheEclipseWorkspace(EclipseToMaven.java:43)
    at com.shri.eclipsetomaven.EclipseToMaven.main(EclipseToMaven.java:26)
    Caused by: java.lang.ClassNotFoundException: org.apache.commons.configuration.ConfigurationException
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    … 10 more

  3. @Manta Please make sure that you are using JDK 7 while running the tool. At the same time also make sure that you have application.properties as specified in the instructions.
    ShriKant Vashishtha recently posted…Enterprise Agile – Are we trying to solve the right problem?My Profile

Leave a Reply

Your email address will not be published. Required fields are marked *

*

CommentLuv badge

Welcome to Sampreshan
Technology Strategist, Speaker, Scrum/XP/Agile Trainer Coach and Trainer
Your interest areas
Follow

Get every new post on this blog delivered to your Inbox.

Join other followers: