I'm working on an automation project for my employer. We have a pool for each revision of our source code. When you download a revision, you need to create a directory structure with a bunch of third party includes to eventually build the project. I've automated this entire process up to the point of having my script (.bat) compile each particular runnable java application. There are many applications to this single project, and the directory listing looks something like this:
我正在为我的雇主做一个自动化项目。我们的源代码的每个版本都有一个池。下载修订时,需要创建一个目录结构,其中包含一堆第三方包含以最终构建项目。我已经将整个过程自动化到让我的脚本(.bat)编译每个特定的可运行java应用程序的程度。这个单一项目有很多应用程序,目录列表如下所示:
Proj Name
-variousincludesfolder1
-variousincludesfolder2
-variousincludesfolder3
-variousincludesfolder4
-runnableapplicationsandmoreincludes
-con.java
Right now, I'd like to do an automated compiling of con.java, but I don't know where to begin. People have suggested I try Ant, but any automated Ant file generation I get using Eclipse seems only enough to build con.java while an active project file exists. Is there anyway to automate this without using eclipse, to the point of having the batch file generate a .jar itself?
现在,我想对con.java进行自动编译,但我不知道从哪里开始。人们建议我尝试使用Ant,但是我使用Eclipse生成的任何自动化Ant文件似乎都足以在存在活动项目文件时构建con.java。反正有没有使用eclipse自动执行此操作,以至于让批处理文件生成.jar本身?
2 个解决方案
#1
This is definitely a job for Ant. Don't rely on Eclipse-generated Ant files; read through the manual and write one yourself. (You'll likely find out that Ant does things you didn't think of doing in your build script, too.)
这绝对是Ant的工作。不要依赖Eclipse生成的Ant文件;仔细阅读手册并自己写一个。 (您可能会发现Ant也会在构建脚本中执行您未想到的操作。)
To be more specific, here is the documentation for the jar task.
更具体地说,这是jar任务的文档。
#2
You can define wildcard and pattern matches to include/exclude all sorts of files and folders in your build. Take a look at the Ant manual to see how things like filesets work with include and exclude filters.
您可以定义通配符和模式匹配,以包含/排除构建中的所有类型的文件和文件夹。查看Ant手册,了解文件集如何与包含和排除过滤器一起使用。
Also, read the tutorial.
另外,阅读教程。
Here is a simple build file that looks to compile all java files and reference all jars. Place it in the top level directory:
这是一个简单的构建文件,它可以编译所有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>
#1
This is definitely a job for Ant. Don't rely on Eclipse-generated Ant files; read through the manual and write one yourself. (You'll likely find out that Ant does things you didn't think of doing in your build script, too.)
这绝对是Ant的工作。不要依赖Eclipse生成的Ant文件;仔细阅读手册并自己写一个。 (您可能会发现Ant也会在构建脚本中执行您未想到的操作。)
To be more specific, here is the documentation for the jar task.
更具体地说,这是jar任务的文档。
#2
You can define wildcard and pattern matches to include/exclude all sorts of files and folders in your build. Take a look at the Ant manual to see how things like filesets work with include and exclude filters.
您可以定义通配符和模式匹配,以包含/排除构建中的所有类型的文件和文件夹。查看Ant手册,了解文件集如何与包含和排除过滤器一起使用。
Also, read the tutorial.
另外,阅读教程。
Here is a simple build file that looks to compile all java files and reference all jars. Place it in the top level directory:
这是一个简单的构建文件,它可以编译所有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>