Search code examples
eclipsemavenantbuildeclipse-jdt

How to generate Ant and Maven build files for an Eclipse Java project?


I have a project which is released like this:

  • Export from Eclipse as a jar file.
  • Package it with exe4j into an EXE file.

Now I am using some static code analysis tool which requires the project to be built with ant or maven.

It seems both Ant and Maven relies on some build file, so how can I generate it from my Eclipse project?

I tried Eclipse Export -> Ant Buildfile, but the exported buildfile seems still relies on Eclipse built-in builder.

Maybe I am wrong but my understanding about a builder server should comprise:

  • Ant
  • JDK
  • Source code to be built

Whenever a new source is checked in, Ant can be launched to build the source with JDK. No eclipse should be involved.

I am new to this. Please shed some light.


Solution

  • The simplest solution is to export to an Ant buildfile in Eclipse by right-clicking on the project and select Export --> Ant Buildfiles.

    This would create a buildfile which contains a default target to build the project, in addition to targets which can be used to run your programs. For example, if you already defined run configurations in Eclipse to run a main method, a target would be created that allows you to run the program from outside Eclipse. If you have defined a JUnit run configuration to run a certain test, the export would also generate a target to run that test from outside.

    Converting to Maven requires more work -- AFAIK there is no official tool or wizard that allows you to generate a full POM configuration from an existing Eclipse project. You can mostly convert to a Maven project by right-clicking on the project and selecting Configure --> Convert to Maven Project but this will only generate a POM file and allow choosing the Maven coordinates. Dependencies and plugin configurations need to be added manually.

    If you still need to add dependencies into your POM automatically based on the project's .classpath, I found this project (haven't tried it though) which seems to do the job.