2

我正在为我的雇主做一个自动化项目。我们的源代码的每个修订版都有一个池。当你下载一个修订版时,你需要创建一个包含一堆第三方包含的目录结构来最终构建项目。我已经自动化了整个过程,直到让我的脚本 (.bat) 编译每个特定的可运行 Java 应用程序。这个项目有很多应用程序,目录列表如下所示:

Proj Name
   -variousincludesfolder1
   -variousincludesfolder2
   -variousincludesfolder3
   -variousincludesfolder4
   -runnableapplicationsandmoreincludes
       -con.java

现在,我想做一个 con.java 的自动编译,但我不知道从哪里开始。人们建议我尝试使用 Ant,但我使用 Eclipse 生成的任何自动 Ant 文件似乎只足以在存在活动项目文件的情况下构建 con.java。无论如何在不使用eclipse的情况下自动执行此操作,以使批处理文件自己生成一个.jar?

4

2 回答 2

6

这绝对是Ant的工作。不要依赖 Eclipse 生成的 Ant 文件;通读手册并自己写一个。(您可能会发现 Ant 也做了您在构建脚本中没有想到的事情。)

更具体地说,这里是 jar task 的文档

于 2009-05-15T19:03:43.917 回答
3

您可以定义通配符和模式匹配以在构建中包含/排除各种文件和文件夹。查看Ant 手册,了解文件集之类的内容如何与包含和排除过滤器一起使用。

另外,阅读教程

这是一个简单的构建文件,它可以编译所有 java 文件并引用所有 jar。将其放在顶级目录中:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" 
    href="http://www.ibm.com/developerworks/xml/library/x-antxsl/examples/example2/ant2html.xsl"?>
<project name="Proj Name" default="build" basedir=".">
    <property name="src.dir" value="${basedir}" description="base folder where the source files will be found.  Typically under /src, but could be anywhere.  Defaulting to root directory of the project" />
    <property name="build.dir" value="build" description="Where to put build files, separate from src and resource files." />

    <path id="master-classpath">
        <fileset dir="${basedir}" description="looks for any jar file under the root directory">
            <include name="**/*.jar" />
        </fileset>
    </path>

    <target name="build" description="Compile all JAVA files in the project">
        <javac srcdir="${src.dir}" 
            destdir="${build.dir}/classes" 
            debug="true" 
            deprecation="true" 
            verbose="false" 
            optimize="false"  
            failonerror="true">
            <!--master-classpath is defined above to include any jar files in the project subdirectories(can  be customized to include/exclude)-->
            <classpath refid="master-classpath"/>
            <!--If you want to define a pattern of files/folders to exclude from compilation...-->
            <exclude name="**/realm/**"/>
        </javac>  
    </target>

</project>
于 2009-05-16T01:24:53.423 回答