Use IntelliJ IDEA to configure Allatori for code obfuscation when developing general Java applications, intellijallatori

Source: Internet
Author: User

Use IntelliJ IDEA to configure Allatori for code obfuscation when developing general Java applications, intellijallatori

Using IntelliJ IDEA to develop general Java applications, code obfuscation through Allatori is very easy to configure. The following summarizes my experience and introduces the configuration methods.

First, create a subdirectory named allatori in the hard disk directory where the IDEA Module is located, and copy all the jar files of Allatori to this subdirectory. Then create two XML files in the directory where the Module of IDEA is located, one is Allatori's own obfuscation configuration file, named config-allatori.xml; the other is the configuration file for Ant build, named build-allatori.xml. First look at the content of the config-allatori.xml file, basically can be used as a template:

 1 <?xml version="1.0" encoding="UTF-8"?> 2 <config> 3     <jars> 4         <jar in="${artifact}" out="${artifact-obfuscated}"/> 5     </jars> 6  7     <classpath> 8         <jar name="lib/mysql-connector-java-5.1.30-bin.jar"/> 9         <jar name="lib/netty-all-4.0.18.Final.jar"/>10         <jar name="../lib/jgoodies-common.jar"/>11         <jar name="../lib/jgoodies-forms.jar"/>12         <jar name="../lib/jna-platform.jar"/>13         <jar name="../lib/jna.jar"/>14     </classpath>15 16     <keep-names>17         <class template="class Launcher">18             <field access="private+"/>19             <method template="private+ *(**)"/>20         </class>21         <class template="interface MacCameraDataCallback">22             <method template="private+ *(**)"/>23         </class>24         <class template="interface MacCameraErrorCallback">25             <method template="private+ *(**)"/>26         </class>27         <class template="interface MacCameraCaptureNativeLibrary">28             <method template="private+ *(**)"/>29         </class>30     </keep-names>31 32     <property name="log-file" value="log.xml"/>33 </config>

Here, my Module contains standard Java classes and interfaces. Launch class Launcher containing the main method should not be confused, and interfaces should not be confused, because local method ing calls involving JNA should be involved, this shows how to set the configuration in the Allatori obfuscation configuration. At the same time, note that in addition to using the proprietary third-party library, this Module also uses the Global third-party library of the project where the Module is located, therefore, in the <classpath> section of the preceding obfuscation configuration, you can see that an accurate third-party library relative or absolute path must be specified for compiling obfuscation. Because Java applications do not need to include third-party libraries into the jar files of the target application as Android applications do, the jar files of third-party libraries also exist independently after compilation, therefore, you do not need to specify a third-party Library Class in the obfuscation configuration to prevent obfuscation.

Next let's take a look at the content of the build-allatori.xml file, you can also be used as a template:

 1 <?xml version="1.0" encoding="UTF-8"?> 2 <project name="MacCameraCaptureTest-allatori" default="MacCameraCaptureTest-obfuscated"> 3     <property name="out.classes.absolute.dir" value="/Users/Dolphin/Develop/idea/PCCameraCaptureInteractivity/out/production/MacCameraCaptureTest"/> 4     <property name="out.jar.absolute.dir" value="/Users/Dolphin/Develop/idea/PCCameraCaptureInteractivity/out/artifacts/MacCameraCaptureTest_jar"/> 5  6     <property name="artifact" value="${out.jar.absolute.dir}/MacCameraCaptureTest.jar"/> 7     <property name="artifact-obfuscated" value="${out.jar.absolute.dir}/MacCameraCaptureTest-obfuscated.jar"/> 8  9     <target name="MacCameraCaptureTest-obfuscated">10         <taskdef name="allatori" classname="com.allatori.ant.ObfuscatorTask" classpath="allatori/allatori.jar"/>11         <allatori config="config-allatori.xml"/>12     </target>13 14     <target name="MacCameraCaptureTest-clean">15         <delete dir="${out.classes.absolute.dir}"/>16         <delete dir="${out.jar.absolute.dir}"/>17     </target>18 </project>

Note that $ {out. classes. absolute. dir} and $ {out. classes. absolute. the IDEA defined by dir}-obfuscated must be accurate for the target class file generated by project Module compilation and the path of the jar file.

Then we need to add the build-allatori.xml to the Ant Build system of IDEA, as shown in:

Click the Ant Build button in the upper-right corner of IDEA, click the "+" button in the pop-up Dock window, and select the build-allatori.xml file to add it to the Ant Build system of IDEA.

Next, go to the IDEA Project Structure configuration, create the Module Artifacts, and in the specific attribute configuration of its Artifacts, you need to specify its Post-processing to use the target defined in the build-allatori.xml with the name "your module name-obfuscated" (I am MacCameraCaptureTest-obfuscated here), as shown in:

Note that in the red area, check the Run Ant target and click "... "button, the selection window appears, you need to select the target defined in the build-allatori.xml named" your module name-obfuscated "(I am MacCameraCaptureTest-obfuscated ).

Click "Build"> "Build Artifacts..." in the IDEA menu and select the "Build" command to compile and Build the Module. You will see two jar files under the Module Artifact generated directory, one of which is named "your Module name-obfuscated. jar "file (here I am the MacCameraCaptureTest-obfuscated.jar), that is, the jar file after obfuscation; without the"-obfuscated "suffix of the jar file is not obfuscated version.

In addition, if you need to clear the class files and jar files generated by the Module (including mixed versions ), you can run the "your module name-clean" target defined in the build-allatori.xml through the Ant Build of IDEA to completely clear them.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.