Work needs, start touching Java, based on N years of C experience, learning a language is not more than 3 things: grammar, compile deployment tool, and public library. Java syntax and C and .Net differences are not big, OO concept is not too different; some special grammatic points, such as Final, GC, and Reflect are discussed everywhere. In view of this, I will focus on the use of public library and compile the deployment tool.
This is a series of blogs, first, some Java-related compilation, configuration tools, and then some common Java open source libraries, and finally Eclipse. Eclipse will be the final footprint. Before it is again, I need some Java foundation, now, starting from Ant.
1. Download, Environmental Configuration: It should be said that Ant's document is compared to large part of C tools and libraries, it is very good. Download ANT to compile from Apache, it takes 20 minutes. Of course, I know that I usually use binary, but since Ant is a build tool, observe that its own compilation process is always a bit interesting. Download Ant, the location is http://ant.apache.org/, unzipped to D disk, the directory structure is as follows: D: /Apache-ant-1.6.2/ bin / DOCS / ETC / LIB SRC / General Follow BIN / Ant.bat is a (Windows Platform), if you are interested, you can analyze the Ant.bat file. I noticed a few rows of scripts: Runant if not "% classpath%" == "" goto runantwithclasspath "% _javacmd%"% Ant_opts% -classpath "% ant_home / lib / ant-launcher.jar" -dant .home =% Ant_HOME% "Org.apache.Tools.ant.launch.launcher% ANT_ARGS%% ANT_CMD_LINE_ARGS% goto End is obvious, org.apache.tools.ant.launch.launcher is an ANT's main function file, search for SRC directory Sure enough, the main function was found in the file launcher.java. 2. View the document, make a configuration file: The core of the compilation process of Ant is to write a build.xml file, which is the makefile file in C . Just, personal feelings of the build.xml file is much simpler than makefile, because most of the work Ant is already done. Less nonsense, the following is a build.xml file I have tested. The results of my test engineering directory are as follows: D: / Test / SRC / DOC / LIB /
Source code is placed in the src directory, and there are several subdirectories, CMD, MSG, and Plugin. Ant itself built-in directory recursive search capabilities, so you can do not consider the existence of subdirectories, of course, if you need fine control compilation process, if you use the tool to generate code, you can automatically generate code, other, here, here, only the simplest Case. I manually written build.xml as follows:
3. Analyze this simple build.xml file: This configuration file is first a Project node with 3 attributes: name represents the name of the Porject, the basedir indicates the starting point of the internal relative path, and the default indicates the target of the Ant default start execution. A build.xml, if the user is knocking Ant in the current directory, then Ant first executes the default target, for the above build.xml, is the third target ---- "run"). Below to analyze the ANT to perform the true process of this build.xml. First, Ant will find the default target - "run". Then Ant discovers the target dependence (Depend) Target corresponding to "Compile", then "Run" into the stack, first execute "" Compile "task. Subsequently, the ANT discovers" Compile "rely on the" init "task, so again Put "Compile", execute "init". "Init" is just a directory in the project root directory. After executing "init", "Compile" out of the stack, executed. "Compile" is executed two steps, first All .java files in the "SRC" directory (handset to search), put the generated .class file into the "build" directory (if there is a recurrent subdirectory, automatically generate the same directory level as the original directory). Compile After completing, package the build directory into a JAR file. "CIMPILE" is complete, starting to execute "run", actually running the project that is just compiled. Of course, if you need to clear the previous compilation, you can simply enter Ant Clear The actual execution process is "Clear" Target is executed, deletes the "build" directory and Test.jar file.
-------------------------------------------------- -------------------------------------------------- ----------------------- or above is a process that I started learning Ant, and the overall feeling of Ant is really very good. Of course, for complex projects, the writing of configuration files may be relatively complicated, but after all, it is easy to maintain Makefile or use Automake to manage makefile.
I am a java newbie, if there is a mistake, welcome to correct, welcome B4.