26

How to convert a Ant project to Maven project? A sample project that would link (a Wicket project)

Thanks

adelarsq
  • 3,718
  • 4
  • 37
  • 47

3 Answers3

25

The nice part of using maven is that most standard stuff works automatically once you do things the maven way. For a simple webapp:

  1. Create a pom with groupId, artifactId and version (packaging: war)
  2. Add the required dependencies to the pom
  3. move the
    • java sources to src/main/java,
    • resources to src/main/resources,
    • webapp content to src/main/webapp,
    • test content to src/test/java and src/test/resources
  4. set the compiler compliance version using the maven compiler plugin

That should get you up 'n' running.

Community
  • 1
  • 1
Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
  • Is it possible to do this without loosing git history for both my "webapp content" and java sources ? I backup and tested a duplicate but it looks like you loose git history for file moves. – steven7mwesigwa Feb 05 '19 at 20:22
5

http://www.sonatype.com/people/2009/04/how-to-convert-from-ant-to-maven-in-5-minutes/

I don't know what your ant script looks like, but assuming its a basic script for building, you will need to create a pom.xml file for your project, add your dependencies, and then build it via maven.

Steven Benitez
  • 10,936
  • 3
  • 39
  • 50
1

For anyone who lands here in future, there is an easier way to find dependencies for maven using the file hashes. So, you won't have to guess artifact versions.

As per the below article, the idea is to generate a SHA1 checksum of the dependency that you want to find the information, then do a reverse search in Nexus repository manager using that hash. For the checksum generation, you can use Microsoft's FCIV (free) utility.

https://dzone.com/articles/ant-to-maven-conversion-the-painless-method

leroneb
  • 75
  • 7
DinushaNT
  • 1,137
  • 6
  • 17
  • A link to a solution is welcome, but please ensure your answer is useful without it: [add context around the link](https://meta.stackexchange.com/a/8259) so your fellow users will have some idea what it is and why it’s there, then quote the most relevant part of the page you're linking to in case the target page is unavailable. [Answers that are little more than a link may be deleted.](https://stackoverflow.com/help/deleted-answers). – Alessio Jul 29 '19 at 09:35
  • Edited the answer – DinushaNT Jul 30 '19 at 05:58