I use eclipse to compile build. xml. You can use other editors, provided that you have installed ant
Merge all. js files in the JS Directory into an all. js file, and call yuicompressor to compress it into a core. js file.
<? XML version = "1.0" encoding = "UTF-8"?> <Project name = "javascritp_build" default = "clean" basedir = ".. /"> <description> javascrui build for ant </description> <property name =" src "location =" JS "/> <property name =" build "location =" build" /> <property name = "target" location = "result"/> <property name = "lib" location = "lib"/> <property name = "charset" value =" UTF-8 "/> <! -----The ant configuration file must go through four processes: 1. Target init performs initialization, create a directory build for temporary file storage. 2. Combine Two JS files with target Concat and put them under the build directory; 3. Target compress calls Yui compressor to compress the merged Js. 4. The target clean operation deletes the generated build directory ant label and attribute explanation: project default corresponds to the name value of a target, which indicates the step to be performed by default; Target's depends corresponds to the name attribute of some other targets, which indicates dependency; $ {name} can reference the value defined in property. Create a directory replaceregexp for the mkdir label, replace the regular expression, and empty the debug ID. If the debug information is not processed in the official environment, set the encoding attribute of the file, otherwise there may be garbled information about ant's detailed documentation. Please refer to the official manual: http://ant.apache.org/manual/-----> <target name = "init"> <mkdir dir = "$ {build}"/> </Target> <target name = "Concat" depends = "init"> <Concat destfile = "$ {build}/All. JS "encoding =" $ {charset} "outputencoding =" $ {charset} "> <Path =" $ {SRC}/core. JS "/> <Path =" $ {SRC}/g. js "/> <Path =" $ {SRC}/nav. js "/> </Concat> <! -----Replaceregexp description http://ant.apache.org/manual/Tasks/replaceregexp.html -------------------> <replaceregexp match = "debug" replace = "" Flags = "G" byline = "true" file = "$ {build}/All. JS "encoding =" $ {charset} "/> </Target> <! -----Yuicompressor parameter: http://developer.yahoo.com/yui/compressor/?work :-H, \-help: displays help information \-type <JS | CSS> specifies the file type of the input file \-charset <charset> specifies the encoding used to read the input file \ -\-line-break <column> insert a line-bread symbol \-V after the specified column, \-verbose displays info and warn level information-O <File> specifies the output file. The default output is the console. Javascript-specific parameters: \-nomunge only compress and do not confuse local variables. \-Preserve-semi keep all semicolons. \-Disable-optimizations cannot be optimized. -----> <Target name = "compress" depends = "Concat"> <echo message = "Start compress" /> <Java jar = "$ {lib}/yuicompressor-2.4.2.jar" fork = "true" failonerror = "false"> <Arg line = "-- Type JS -- charset $ {charset }-- nomunge $ {build}/All. JS-o $ {target}/core. JS "/> </Java> <echo message =" End compress "/> </Target> <target name =" clean "depends =" compress "> <Delete dir =" $ {build} "/> </Target> </Project>
Right-click build. xml and select Run as ---> ant build. The following information is displayed on the console if the build is successful:
Buildfile: C: \ java_app \ javatest \ webroot \ WEB-INF \ ant-build \ build. xml
Init:
[Mkdir] created dir: C: \ java_app \ javatest \ webroot \ WEB-INF \ build
Concat:
Compress:
[Echo] Start Compress
[Echo] End Compress
Clean:
[Delete] deleting directory c: \ java_app \ javatest \ webroot \ WEB-INF \ build
Build successful
Total time: 1 second
For more information about ant + jslint, see www.rabbler.org/archives/40.