How to build a legacy C++ project with Apache Maven ?

Let’s say you have a legacy C/C++ project that is presently being compiled with make utility. Assuming you would like to mavenize your project with no or minimal change, here is a way you can achieve this with ease.

Let’s first create a simple C++¬†class header as below

Let’s go ahead and define the class in hello.cpp

Let’s write the main function in main.cpp

Now its time to create a Makefile

At this point your project home folder should look as below

Screen Shot 2016-08-08 at 9.46.26 PM

You should be able to compile your project as below

Screen Shot 2016-08-08 at 9.49.50 PM

Now let’s assume this is our legacy project which already works fine but you would like to build this legacy project with Maven moving forward.

Let’s create the pom.xml file in the project home as shown below

With the above pom.xml in place, you should be able to compile the C++ project as below

Screen Shot 2016-08-08 at 10.01.56 PM

Share Now

Jegan

More Posts By Jegan

Related Post

Leave us a reply