Creating C ++ and Java code using CMake and Maven and a bundle in the bank

I have inherited C ++ code that is generated using CMake. It generates a .so file. I need to wrap this code in Java and create a jar that includes Java code, as well as C ++ for deployment.

The steps to create C ++ code using CMake are simple:

cd /to/pkg/dir cmake . make 

The .so file is created in the build / directory. If I convert the entire project to maven, I will have to change the directory structure (here is a blog that explains how this can work http://blog.bigpixel.ro/2012/07/building-cc-applications-with-maven/ ) . However, I do not want to do this. Could it be possible to call the first two lines shown above from maven to create a .so file and then include it in the last jar? Thanks in advance.

+7
java c ++ maven
source share
1 answer

In Apache Hadoop, the assembly does something similar to what you described. We use the Apache Maven AntRun Plugin at compile time to make an external call to cmake , and then call make on the generated output using CMake to compile and link part C of our codebase. This output is then loaded into our final build artifacts. In our case, those that create artifacts are tarballs, not directly linked to a jar file, but you can execute it by controlling the configuration of the Apache Maven JAR Plugin . In particular, you may need to override the content to enable / exclude settings .

If you want to use it as a starting point, the corresponding part of the Hadoop assembly is visible here:

https://github.com/apache/hadoop/blob/release-2.7.3-RC2/hadoop-common-project/hadoop-common/pom.xml#L598-L615

 <execution> <id>make</id> <phase>compile</phase> <goals><goal>run</goal></goals> <configuration> <target> <exec executable="cmake" dir="${project.build.directory}/native" failonerror="true"> <arg line="${basedir}/src/ -DGENERATED_JAVAH=${project.build.directory}/native/javah -DJVM_ARCH_DATA_MODEL=${sun.arch.data.model} -DREQUIRE_BZIP2=${require.bzip2} -DREQUIRE_SNAPPY=${require.snappy} -DCUSTOM_SNAPPY_PREFIX=${snappy.prefix} -DCUSTOM_SNAPPY_LIB=${snappy.lib} -DCUSTOM_SNAPPY_INCLUDE=${snappy.include} -DREQUIRE_OPENSSL=${require.openssl} -DCUSTOM_OPENSSL_PREFIX=${openssl.prefix} -DCUSTOM_OPENSSL_LIB=${openssl.lib} -DCUSTOM_OPENSSL_INCLUDE=${openssl.include} -DEXTRA_LIBHADOOP_RPATH=${extra.libhadoop.rpath}"/> </exec> <exec executable="make" dir="${project.build.directory}/native" failonerror="true"> <arg line="VERBOSE=1"/> </exec> <!-- The second make is a workaround for HADOOP-9215. It can be removed when version 2.6 of cmake is no longer supported . --> <exec executable="make" dir="${project.build.directory}/native" failonerror="true"></exec> </target> </configuration> </execution> 
+7
source share

All Articles