使用诸如Ant或Maven之类的构建工具。与使用
findUNIX工具相比,这两种方法都可以使您以更好的方式管理依赖关系。And和Maven都还允许您定义除编译之外要执行的自定义任务。Maven还附带了用于管理远程存储库中的外部依赖项的约定,以及用于运行单元测试和支持连续集成的功能的约定。
即使您只需要偶尔编译一次源文件,您也可能会发现,设置一个简单的Ant
build.xml文件最终可以节省大量时间。
最后,大多数流行的IDE和代码编辑器应用程序都与Ant构建脚本进行了某种形式的集成,因此您可以在编辑器中运行所有Ant任务。NetBeans,Eclipse,IDEA等还具有对Maven的内置支持。
如果您是Ant的新手,请先阅读本文。以下是链接中的示例构建文件:
<project name="MyProject" default="dist" basedir="."> <description> simple example build file </description> <!-- set global properties for this build --> <property name="src" location="src"/> <property name="build" location="build"/> <property name="dist" location="dist"/> <target name="init"> <!-- Create the time stamp --> <tstamp/> <!-- Create the build directory structure used by compile --> <mkdir dir="${build}"/> </target> <target name="compile" depends="init" description="compile the source " > <!-- Compile the java pre from ${src} into ${build} --> <javac srcdir="${src}" destdir="${build}"/> </target> <target name="dist" depends="compile" description="generate the distribution" > <!-- Create the distribution directory --> <mkdir dir="${dist}/lib"/> <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file --> <jar jarfile="${dist}/lib/MyProject-${DSTAMP}.jar" basedir="${build}"/> </target> <target name="clean" description="clean up" > <!-- Delete the ${build} and ${dist} directory trees --> <delete dir="${build}"/> <delete dir="${dist}"/> </target></project>熟悉Ant之后,您会发现迁移到Maven更容易。



