简体   繁体   English

使用Ant构建多个jar

[英]Using Ant to build multiple jars

I have multiple Java eclipse projects. 我有多个Java eclipse项目。 Each of them has "jardesc" file for building jar. 他们每个人都有“jardesc”文件用于构建jar。 It's nice - double click -> finish and jar file is made. 这很好 - 双击 - >完成并制作jar文件。 But when i have to export several jars it's a pain - i have to repeat procedure several times. 但是,当我必须出口几个罐子时,这是一个痛苦 - 我必须重复几次程序。 Please tell me, can i use Ant script to run several "jardesc" files at once (and get several jars according to each jardesc file)? 请告诉我,我可以使用Ant脚本一次运行几个“jardesc”文件(并根据每个jardesc文件获取几个罐子)? How to do it? 怎么做?

You could use the jar target to make the jars for you: 您可以使用jar目标为您制作罐子:

    <jar destfile='destination.jar' basedir='source\dir\' />

so your build.xml would look a little like this: 所以你的build.xml看起来有点像这样:

    <project default="makejars">
        <target name="makejars">
            <jar destfile="app1.jar" basedir="app1\src\" />
            <jar destfile="app2.jar" basedir="app2\src\" />
            <jar destfile="app3.jar" basedir="app3\src\" /> 
        </target>
    </project>

then just run ant in the same directory as build.xml, and the jars should be made. 然后在与build.xml相同的目录中运行ant,并且应该创建jar。

Take a look at subant task in ant. 看看ant中的subant任务。 You can create ant-file which would call other files to. 您可以创建将调用其他文件的ant文件。

    <subant target="create_jar1">
        <fileset dir="." includes="jar2.xml"/>
    </subant>
    <subant target="create_jar2">
        <fileset dir="." includes="jar1.xml"/>
    </subant>

您可以使用一些循环来创建ant参数,但是没有办法循环创建多个jar (即使使用ant-commons扩展),复制和粘贴是唯一可行的解​​决方案, 除非您想编写一个ant插件 (它没有'真的花了2个小时阅读docs +写简单的插件)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 清洁方式结合多个罐子?最好使用Ant - Clean way to combine multiple jars? Preferably using Ant 如何在类路径中使用ant包含多个jar? - How can include multiple jars in the classpath using ant? 使用蚂蚁编译嵌套罐子 - compiling nested jars using ant 在蚂蚁构建期间不包括依赖项目的罐子 - Excluding jars of dependency project during ant build 是否可以使用ANT构建文件访问/添加远程位置jar到项目中? - Is it possible to access/add remote location jars to the projects using ANT build file? 后续第2部分 - 使用Maven仅签名和部署jar到Maven Central。 构建和编译完全由Ant完成 - Followup part 2 — Using Maven to only sign and deploy jars to Maven Central. Build and compilation is done entirely with Ant 使用Ant Build脚本创建WarFile时,如何在WEB-INF / lib文件夹中包含Classpath jars - How to include Classpath jars in WEB-INF/lib Folder while creating a WarFile using Ant Build Script 后续问题:使用Maven仅签名jar并将其部署到Maven Central。 构建和编译完全由Ant完成 - Followup questions: Using Maven to only sign and deploy jars to Maven Central. Build and compilation is done entirely with Ant 如何在使用build.xml文件的Ant生成的jar文件中包含Eclipse项目的“Java Build Path”部分中引用的jar文件 - How to include the jars referenced in “Java Build Path” section of an Eclipse project in a jar file generated with Ant using a build.xml file 用蚂蚁打造多个战争 - Multiple war build with ant
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM