Build a Java executable with Ant

zhaozj2021-02-16  47

Build a Java executable with Ant

Ant is now a better management tool now, and you can manage your own projects in your own needs via Ant.

Step 1: Configure your own tools J2SDK and Ant.j2sdk Download. Download them at http://www.apache.org. Set the environment variable java_home = E: /J2SDK1.4.1 ; And ant_home = E: / Ant; Path = E: /J2SDK1.4.1_04/bin; E: / Ant / bin

Step 2: Ant needs a build.xml file when compiling. In addition to make the program to facilitate porting to other aspects, do a build.properties file to save the basic properties of Ant.

The basic attribute file of Ant is as follows:

The specific properties are as follows:

# This document is used to set some common properties

# 档 name

Name = HelloWorld

# 合 合 后 j

JAR = $ {name} .jar

# 原用 档 所 所 路

Src.dir = SRC

# 资 资 所 所 路

Res. Dir = Res

# Modeling product storage location

Build.dir = build

# Compile the post-storement location

Build.dir.classes = $ {build.dir} / classes

#jar final placement position

Build.dir.bin = $ {build.dir} / bin

# Unlamished JAR file name

Build.dir.bin.jarunobfus = $ {build.dir.bin} / $ {name} -unobfus.jar

# Confused JAR file name

Build.dir.bin.jar = $ {build.dir.bin} / $ {jar}

#Jdk's path

Java.home = E: /J2SDK1.4.1_04

#JDK The path where the inside the instrument

Java.home.bin = $ {java.home} / bin

# 混淆 控制 控制

Obfuscator.lib = retroguard.jar

Obfuscator.script = script.rgs

Step 3: Establish build.xml. To compile it with Ant to generate files.

The specific properties in build.xml are:

Mkdir is a directory. Delete is a deleted directory. Command, basedir is the directory where to pack files, JARFile is compiled, which is not generated after the obfuscator. Manifest.mf is a menu file, which contains the desired class executed. FileSet is a directory where the resource file is located. Java is a list of confused, the original target JAR file, the confused JAR file, the confusing list. The obfuscator is used by the Open source's retroguard. That is at http://www.retrology. Setting a retroguard.jar file path in ClassPath.depends attribute is the interdependent relationship between Target. Just perform the DEFAULT property is the parameter executed by Ant defaults. Ant and ANT ALL are the same.

SRCDIR = "$ {src.dir}"

destdir = "$ {build.dir.classes}"

/>

JARFILE = "$ {build.dir.bin.jarunobfus}"

Manifest = "manifest.mf">

Step 4: Write a source file. Put it in the SRC directory.

Step 5: Write menu files Manifest.mf, main is the primary class. Demo is package.

Main-class: demo.main

Step 6: Write a list of obfuscors Script.rgs

.CLASS DEMO / Main public

This main.class will not be confused.

Step 7: Perform an ANT command under build.xml. If the GUI program is the GUI program in the SRC directory, the GUI program can be executed in the build / bin.

转载请注明原文地址:https://www.9cbs.com/read-23201.html

New Post(0)