Maven is perhaps the most widely-used project management tool for Java. Based on the Project Object Model (POM), it is used not only for compilation of source code, but also dependency management, documentation, running tests, packaging, deployment, and more. We are frequently asked if we have a Maven plugin for running DashO. Though we do not offer a specific Maven plugin, adding DashO to your Maven-based project is surprisingly easy by leveraging Ant.
Please consider this basic pom.xml, which I use to compile a runnable jar file with resources.
To protect my code, I’ll use the Maven AntRun plugin with an Ant target to call to DashO. We may prefer to externalize our Ant script as a separate build.xml, but this is simple enough that I’ve added it directly to my pom.xml
Before calling DashO, my Ant target renames the original Maven-packaged jar to “-unprotected” and provides this as input to DashO. DashO will output the original jar name. This step ensures we always deploy a protected jar.
Rather than hard-coding the DashO input and output, I’ll provide “inputjar” and “outputjar” properties, which will expand at build time. From my DashO project.dox file:
Now, when we run the package, deploy, or install phase, we will see DashO logging in the output:
And we will have an obfuscated version of our Jar file when the build completes.
The full Maven project for this sample can be downloaded here.
This project is simple, but the concept can be translated to more complex Maven projects. We will ultimately leverage Ant to provide an obfuscated package directly from our Maven build.
If you have any feedback on this topic or other topics you would like us to discuss in the Support Corner, please contact us at support [at] preemptive [dot] com.