Skip to content

Instantly share code, notes, and snippets.

@hkneptune
Last active May 27, 2019 09:05
Show Gist options
  • Save hkneptune/9decb71432fff8ba362396ec71aba66a to your computer and use it in GitHub Desktop.
Save hkneptune/9decb71432fff8ba362396ec71aba66a to your computer and use it in GitHub Desktop.
Configure Obfuscation with the PreEmptive Protection DashO in Apache Maven Project

Configure Obfuscation with the PreEmptive Protection DashO in Apache Maven Project

Prerequisites

  1. Download DashO for Android & Java on PreEmptive Solutions and then extract it into a local directory. For example: C:\programming\DashO-9.3.0.
  2. Activate the DashO with DashOGUI.
  3. Download Open Java Development Kit (OpenJDK) and then extract it into a local directory. For example: C:\Java\jdk-11.0.2.
  4. Dwonload Apache Maven and then extract it into a local directory. For example: C:\programming\apache-maven-3.6.1.
  5. Configure the user variable DASHO_HOME, DASHO_JAVA_HOME, JAVA_HOME, MAVEN_HOME.
DASHO_HOME=C:\programming\DashO-9.3.0
DASHO_JAVA_HOME=C:\Java\jdk-11.0.2
JAVA_HOME=C:\Java\jdk-11.0.2
MAVEN_HOME=C:\programming\apache-maven-3.6.1
  1. Configure the system variable PATH, add the following links.
C:\Java\jdk-11.0.2\bin
C:\programming\apache-maven-3.6.1\bin

Build Maven Project with DashO

Method 1 (Use of Apache Maven AntRun Plugin)

  1. Open pom.xml, add the following code to plugins tag.
<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.8</version>
    <executions>
        <execution>
            <id>obfuscate</id>
            <phase>package</phase>
            <configuration>
                <target>
                    <dependencyfilesets />
                    <property name="PARAM_KEY">PARAM_VALUE</property>
                    <typedef resource="preemptive/dasho/anttask/antlib.xml" classpathref="maven.plugin.classpath" />
                    <ant antfile="ant.build.xml">
                        <target name="dasho" />
                    </ant>
                </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>preemptive.dasho</groupId>
            <artifactId>ant-dasho</artifactId>
            <version>9.3.0</version>
        </dependency>
        <dependency>
            <groupId>preemptive.dasho</groupId>
            <artifactId>doxfile</artifactId>
            <version>9.3.0</version>
        </dependency>
        <dependency>
            <groupId>preemptive.dasho</groupId>
            <artifactId>xsdlib</artifactId>
            <version>9.3.0</version>
        </dependency>
        <dependency>
            <groupId>preemptive.dasho</groupId>
            <artifactId>relaxngDatatype</artifactId>
            <version>9.3.0</version>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.3.1</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
            <version>2.3.2</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-libs</artifactId>
            <version>1.0.6</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
        </dependency>
        <dependency>
            <groupId>org.apache.ant</groupId>
            <artifactId>ant</artifactId>
            <version>1.10.6</version>
        </dependency>
    </dependencies>
</plugin>
  1. Use the property tag to pass the KEY and VALUE pair to ant buildfile.
  2. Change the ant buildfile path in the ant tag.
  3. Set the ant target in the target tag.
  4. Add the following target in the ant buildfile.
<target name="dasho">
    <java fork="true" classname="DashOPro" classpath="${env.DASHO_HOME}/DashOPro.jar" failonerror="true">
        <jvmarg value="-Djava.awt.headless=true" />
        <arg value="-v" />
        <arg file="dasho.obfuscate.dox" />
        <sysproperty key="PARAM_KEY" value="PARAM_VALUE" />
    </java>
</target>
  1. Change the value of arg tag with the property file to the DashO project file path.
  2. Use the sysproperty tag to pass the KEY and VALUE pair to DashO project.

Method 2 (Use of MojoHaus Exec Maven Plugin)

  1. Open pom.xml, add the following code to plugins tag.
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.6.0</version>
    <executions>
        <execution>
            <id>DashO</id>
            <phase>package</phase>
            <goals>
                <goal>exec</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <executable>java</executable>
        <arguments>
            <argument>-Xms512m</argument>
            <argument>-Xss1m</argument>
            <!-- <argument>-verbose:gc</argument> -->
            <argument>-Djava.awt.headless=true</argument>
            <argument>-DPARAM_KEY=PARAM_VALUE</argument>
            <argument>-jar</argument>
            <argument>${env.DASHO_HOME}/DashOPro.jar</argument>
            <argument>--quiet</argument>
            <argument>dasho.obfuscate.dox</argument>
        </arguments>
    </configuration>
</plugin>
  1. Use the argument tag with -D as the value prefix to pass the KEY and VALUE pair to DashO project.
  2. Update the last argument element to the DashO project file path.

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment