是否有任何ANT功能,即复制类路径依赖于WEB-INF / lib目录? [英] Is there any ANT feature, that copies classpath dependencies to WEB-INF/lib?

查看:308
本文介绍了是否有任何ANT功能,即复制类路径依赖于WEB-INF / lib目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在不影响复制类路径依赖的过程,WEB-INF / lib目录分类:有没有那份那些罐子(至少,我找不到任何复制任务与相关的WEB-INF特殊Ant任务/ lib目录字符串作为路径参数),但项目建成后出现。如何影响这个过程?基本上,我需要排除JAXB罐,以避免冲突的依赖。同时我需要这个罐子在编译时,所以我不能将其删除。也许,更容易消除手动那些罐子,使用删除任务?

I can't affect the procedure of copying classpath dependencies to WEB-INF/lib category: there is no special ANT task that copies those jars (at least, i cant find any 'copy' task with related "WEB-INF/lib" string as PATH argument), but they appeared after project building. How to affect this procedure? Basically, i need to exclude JAXB jars to avoid dependency conflict. At the same time i need this jars at compile-time, so i can't remove them. Maybe, it is easier to erase those jars manually, using 'delete' task?

推荐答案

与挣扎什么是多类路径管理。在一个典型的构建至少有4种类型的类路径:

What your struggling with is multiple classpath management. In a typical build there are at least 4 types of classpath:


  • 编译:类,你的code直接调用

  • 运行:类,你的code通过其他类间接调用

  • 提供:你需要进行编译的类,但其实施将在目标平台来提供

  • 测试:当你正在测试code所需要但其他类(比如JUnit的)不随最终应用程序

  • compile: Classes that your code directly invokes
  • runtime: Classes that your code indirectly invokes via other classes
  • provided: Classes that you need to compile against, but whose implementation will be provided by the target platform
  • test: Additional classes (like junit) that are needed when you're testing code but which are not shipped with your final application

这是的Maven构建的工具,它正式确定这些常见的类路径和解决提供了一个依赖的管理制度和在构建过程中填充的classpath。

It was the Maven build tool which formally identified these common classpaths and provided a dependency management system for resolving and populating classpaths during the build process.

坏消息是,ANT pre-日期 Maven的并因此彻底离开管理类路径可达程序员....典型地,这是通过将瓶子成不同的目录或使用构建逻辑内复杂的文件集完成。

The bad news is that ANT pre-dates Maven and therefore leaves classpath management completely up to the programmer.... Typically this is done by putting jars into different directories or using complicated filesets within your build logic.

好消息是,有一个叫ANT插件常春藤它执行的Maven般的依赖管理。这是值得我们学习,尤其是,如果你使用开源库编写了很多(这越来越多使用Maven现在)。

The good news is that there is an ANT plugin called ivy which performs Maven-like dependency management. It's worth learning, especially, if you program a lot with open source libraries (which increasingly use Maven now).

它弥补了个人类路径的文件必须在构建顶部进行管理。显然,这些文件必须单独下载到lib目录。作为文件的数量增加了这种方法变得笨重。

The files which make up the individual classpaths must be managed at the top of the build. Obviously the files must be separately downloaded into the "lib" directory. As the number of files increases this approach becomes unwieldy.

<project name="demo" default="build">

    <!-- 
    ================
    File collections 
    ================
    -->
    <fileset dir="lib" id="compile.files">
        <include name="*.jar"/>
        <exclude name="slf4j-log4j12.jar"/>
        <exclude name="log4j.jar"/>
        <exclude name="junit.jar"/>
        <exclude name="hamcrest-core.jar"/>
    </fileset>

    <fileset dir="lib" id="runtime.files">
        <include name="*.jar"/>
        <exclude name="junit.jar"/>
        <exclude name="hamcrest-core.jar"/>
    </fileset>

    <fileset dir="lib" id="test.files">
        <include name="*.jar"/>
    </fileset>

    <!--
    ===============
    Compile targets
    ===============
    -->
    ..
    ..

    <target name="compile" depends="init,resolve, resources" description="Compile code">
        <mkdir dir="${classes.dir}"/>
        <javac srcdir="${src.dir}" destdir="${classes.dir}" includeantruntime="false" debug="true">
            <classpath>
                <fileset refid="compile.files"/>
            </classpath>
        </javac>
    </target>

    <!--
    ===============
    Distribution targets
    ===============
    -->
    ..
    ..

    <target name="package" depends="test" description="Create the WAR file">
        <copy todir="build/lib">
            <fileset refid="runtime.files"/>
        </copy>

        <war destfile="${war.file}" webxml="${resources.dir}/web.xml">
            <fileset dir="${resources.dir}" excludes="web.xml"/>
            <lib dir="${build.dir}/lib"/>
        </war>
    </target>

为例(使用常春藤)

非常高层次的介绍Ivy和它的任务。请参阅检索常青藤任务下面它提供你正在寻找的功能。

Example (Using ivy)

Very high level introduction to ivy and it's tasks. See the "retrieve" ivy task below which delivers the functionality you're looking for.

<project name="demo" default="build" xmlns:ivy="antlib:org.apache.ivy.ant">

    <!--
    ===========
    Build setup
    ===========
    -->
    <target name="bootstrap" description="Install ivy">
        <mkdir dir="${user.home}/.ant/lib"/>
        <get src="http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.2.0/ivy-2.2.0.jar"
             dest="${user.home}/.ant/lib/ivy.jar"/>
    </target>

    <!--
    ============================
    Resolve project dependencies
    ============================
    -->
    <target name="resolve" description="Use ivy to resolve classpaths">
        <ivy:resolve/>

        <ivy:report todir='${ivy.reports.dir}' graph='false' xml='false'/>

        <ivy:cachepath pathid="compile.path" conf="compile"/>
        <ivy:cachepath pathid="runtime.path" conf="runtime"/>
        <ivy:cachepath pathid="test.path"    conf="test"/>
    </target>

    <!--
    ===============
    Compile targets
    ===============
    -->
    ..
    ..

    <target name="compile" depends="init,resolve, resources" description="Compile code">
        <mkdir dir="${classes.dir}"/>
        <javac srcdir="${src.dir}" destdir="${classes.dir}" includeantruntime="false" debug="true" classpathref="compile.path"/>
    </target>

    <!--
    ===============
    Distribution targets
    ===============
    -->
    ..
    ..

    <target name="package" depends="test" description="Create the WAR file">
        <ivy:retrieve pattern="${build.dir}/lib/[artifact].[ext]" conf="runtime"/>

        <war destfile="${war.file}" webxml="${resources.dir}/web.xml">
            <fileset dir="${resources.dir}" excludes="web.xml"/>
            <lib dir="${build.dir}/lib"/>
        </war>
    </target>

备注


  • 在引导的目标是设计安装常春藤(它不与ANT核心封装)

  • 在cachepath任务用于创建自定义的ANT路径

  • 在检索任务填充WAR文件的WEB-INF / lib目录在运行时所需要的jar文件目录(常春藤配置管理)

该文件列出了项目的依赖。它使用的配置逻辑分组罐子在一起,使常青藤cachpath任务到您的构建中创建匹配的类路径。最后,第三方jar文件被下载并在生成过程中缓存。这是非常方便的,这意味着可以减少项目的大小。

This file lists your project's dependencies. It uses configurations to logically group jars together and enables the ivy "cachpath" task to create matching classpaths within your build. Finally the 3rd party jars are downloaded and cached during the build process. This is very convenient and it means you can reduce the size of your project.

<ivy-module version="2.0">
    <info organisation="com.myspotontheweb" module="demo"/>

    <configurations>
        <conf name="compile" description="Required to compile application"/>
        <conf name="runtime" description="Additional run-time dependencies" extends="compile"/>
        <conf name="test"    description="Required for test only" extends="runtime"/>
    </configurations>

    <dependencies>
        <!-- compile dependencies -->
        <dependency org="org.slf4j" name="slf4j-api" rev="1.7.2" conf="compile->default"/>

        <!-- runtime dependencies -->
        <dependency org="org.slf4j" name="slf4j-log4j12" rev="1.7.2" conf="runtime->default"/>

        <!-- test dependencies -->
        <dependency org="junit" name="junit" rev="4.10" conf="test->default"/>
    </dependencies>

</ivy-module>

这篇关于是否有任何ANT功能,即复制类路径依赖于WEB-INF / lib目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆