使用ant创建ear文件

发布于 2024-11-03 14:27:55 字数 433 浏览 0 评论 0原文

我是 ant 的新手,我提到了很多网站,我需要为我的项目构建 build.xml,其中包括 在两个模块中,我有 application.xml 文件,它代表相应的 war 文件

,所以我的问题是添加 application.xml 文件就足够了,

<ear destfile="${dist.dir}/${ant.project.name}.ear" appxml="${conf.dir}/application.xml">  
 <metainf dir="${build.dir}/META-INF"/> 
 <fileset dir="${dist.dir}" includes="*.jar,*.war"/>
</ear>

这是否会引用相应的 war 文件,或者我需要编译整个场景,请告诉我。怎么解决这个问题。

I am new to ant i referred many sites , i need to build.xml for my project which consists
of two modules i have application.xml file which represents corresponding war file

so my question is it sufficient to add the application.xml file

<ear destfile="${dist.dir}/${ant.project.name}.ear" appxml="${conf.dir}/application.xml">  
 <metainf dir="${build.dir}/META-INF"/> 
 <fileset dir="${dist.dir}" includes="*.jar,*.war"/>
</ear>

whether this will refer the corresponding war files or i need to compile the whole scenario please let me know. how solve this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海螺姑娘 2024-11-10 14:27:55

我不是 100% 确定你在问什么。

为了使用 任务,您需要编译所需的 jar 和 wars。

如果这些 jars 和 wars 已经构建,您只需在 任务中引用它们,就像在示例中所做的那样。在构建 Ear 之前,application.xml 必须已经存在。 application.xml 不会构建 jars 和 wars,你必须这样做。

如果您还没有构建 wars 和 jars,则需要先这样做。 build.xml 的总体轮廓如下所示:

<project name="foo" basedir="." default="package">

    <!-- Some standard properties you've defined -->
    <property name="target.dir" value="${basedir}/target"/>
    <property name="xxx" value="yyy"/>
    <property name="xxx" value="yyy"/>
    <property name="xxx" value="yyy"/>

    <!-- Compile properties that allow overrides -->

    <property name="javac.nowarn" value="false"/>
    <property name="javac.listfiles" value="false"/>
    <property name="javac.srcdir" value="source"/>
    <property name="javac.distdir" value="${target.dir}/classes"/>


    <target name="clean"
        description="cleans everything nice and shiny">
        <delete dir="${target.dir}"/>
    </target>

    <target name="compile"
        description="Compiles everything">

        <mkdir dir="${javac.distdir}"/>
        <javac srcdir="${javac.srcdir}"
            destdir="${javac.destdir}"
            [...]
            [...]/>
    </target>

    <target name="package.jar"
        depends="compile"
        description="Package jarfile">

        <jar destfile="${target.dir}/jarname.jar"
            [...]
            [...]/>
    </target>

    <target name="package.jar2"
        depends="compile"
        description="Package jarfile">

        <jar destfile="${target.dir}/jarname2.jar"
            [...]
            [...]/>
    </target>

    <target name="package.war"
        depends="compile"
        description="Package jarfile">

        <war destfile="${target.dir}/jarname.jar"
            [...]
            [...]/>
    </target>

    <target name="package"
        depends="package.jar"
        description="Make the ear">

        <ear destfile="${target.dir}/earfile.ear"
            [...]/>
    </target>
</project>

基本上,它由一堆目标组成,每个目标执行一项任务。您可以让目标依赖于其他目标。例如,这个特定的 build.xml 将自动运行 package 任务。 package 任务依赖于package.jar 任务,而package.jar 任务又依赖于compile 任务。因此,build.xml 文件将首先调用compile,然后调用package.jar,最后调用package

需要记住的重要一点是,您没有指定事件的顺序。你让 Ant 弄清楚这一点,你也让 Ant 弄清楚你需要做什么。假设您修改了 java 源文件。 Ant 知道它只需重新编译该一个文件。它还知道可能必须重建包含该类文件的 jar 文件。然后它知道必须重建耳朵。大多数任务可以自行解决,并且您不必为每个构建执行clean。 (您会注意到 clean 目标不是由 packagecompile 调用的。您必须手动调用它)。

我唯一建议的另一件事是尽量保持工作区域清洁。您创建的任何文件都应放入 ${target.dir} 目录中。这样,当您执行clean时,您只需删除该一个目录。

我希望这能回答你的问题。

I'm not 100% sure what you're asking.

In order to use the <ear> task, you already need to have compiled the required jars and wars.

If those jars and wars have already been built, you simply refer to them in your <ear> task as you did in your example. The application.xml must already exist before you build your ear. The application.xml doesn't build the jars and wars, you have to do that.

If you haven't already built the wars and jars, you need to do that first. A general outline of a build.xml looks something like this:

<project name="foo" basedir="." default="package">

    <!-- Some standard properties you've defined -->
    <property name="target.dir" value="${basedir}/target"/>
    <property name="xxx" value="yyy"/>
    <property name="xxx" value="yyy"/>
    <property name="xxx" value="yyy"/>

    <!-- Compile properties that allow overrides -->

    <property name="javac.nowarn" value="false"/>
    <property name="javac.listfiles" value="false"/>
    <property name="javac.srcdir" value="source"/>
    <property name="javac.distdir" value="${target.dir}/classes"/>


    <target name="clean"
        description="cleans everything nice and shiny">
        <delete dir="${target.dir}"/>
    </target>

    <target name="compile"
        description="Compiles everything">

        <mkdir dir="${javac.distdir}"/>
        <javac srcdir="${javac.srcdir}"
            destdir="${javac.destdir}"
            [...]
            [...]/>
    </target>

    <target name="package.jar"
        depends="compile"
        description="Package jarfile">

        <jar destfile="${target.dir}/jarname.jar"
            [...]
            [...]/>
    </target>

    <target name="package.jar2"
        depends="compile"
        description="Package jarfile">

        <jar destfile="${target.dir}/jarname2.jar"
            [...]
            [...]/>
    </target>

    <target name="package.war"
        depends="compile"
        description="Package jarfile">

        <war destfile="${target.dir}/jarname.jar"
            [...]
            [...]/>
    </target>

    <target name="package"
        depends="package.jar"
        description="Make the ear">

        <ear destfile="${target.dir}/earfile.ear"
            [...]/>
    </target>
</project>

Basically, it consists of a bunch of targets and each target does one task. You can have targets depend upon other targets. For example, this particular build.xml will automatically run the package task. The package task depends upon the package.jar task which depends upon the compile task. Thus, the build.xml file will first call compile, then package.jar, then package.

The important thing to remember is that you don't specify the order of the events. You let Ant figure that out, and you let Ant figure out what you need to do. Let's say you've modified a java source file. Ant knows that it has to recompile only that one file. It also knows that it might have to rebuild the jarfile that contains that classfile. And, it then knows it has to rebuild the ear. Most tasks can figure it out on their own, and you don't do a clean for each build. (You notice that the clean target isn't called by package or compile. You have to call it manually).

The only other thing I recommend is that you try to keep your work area clean. Any files you create should be put into the ${target.dir} directory. That way, when you do a clean, you only have to delete that one directory.

I hope this answer your question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文