Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何向Ant项目添加依赖项_Ant - Fatal编程技术网

如何向Ant项目添加依赖项

如何向Ant项目添加依赖项,ant,Ant,我想在我的Ant项目中添加依赖项;例如,我想将hibernate依赖项添加到我的项目中 我是新来的蚂蚁。在我使用maven工具构建项目之前。 在maven中,很容易向pom.xml文件添加依赖项 My build.xml文件 <?xml version="1.0" encoding="UTF-8"?> <project name="Demo ANT Project-1" default="run"> <target name="run" depends="

我想在我的Ant项目中添加依赖项;例如,我想将hibernate依赖项添加到我的项目中

我是新来的蚂蚁。在我使用maven工具构建项目之前。 在maven中,很容易向
pom.xml
文件添加依赖项

My build.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<project name="Demo ANT Project-1" default="run">

    <target name="run" depends="compile">
        <java classname="com.company.product.RoundTest">
        <classpath path="staging"/>
        </java>
    </target>


    <target name="compile">
        <javac includeantruntime="false" srcdir="./src" destdir="staging" />
    </target>
</project>

我想向上述Ant xml文件添加依赖项

请注意:这个问题是6年前新提出和回答的

首先,Ant比Maven旧,因此不包括对依赖关系管理的核心支持

添加常春藤 Ivy是Ant的依赖关系管理框架

要启用它,您需要做两件事。首先,将ivy任务名称空间包含到构建文件的顶部:

<project .... xmlns:ivy="antlib:org.apache.ivy.ant">
然后可以在javac任务中使用这个ivy管理的类路径

<javac includeantruntime="false" srcdir="./src" destdir="staging" classpathref="compile.path"/>

还是把所有东西都放在一个蚂蚁目标中

<target name="update-lib-dir">
    <property name="ivy.install.version" value="2.4.0"/>
    <property name="ivy.jar.file" value="lib-ant/ivy-${ivy.install.version}.jar"/>
    <property name="lib-ivy.dir" value="lib-ivy"/>
    <get src="https://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar"
        dest="${ivy.jar.file}" usetimestamp="true" />

    <taskdef resource="org/apache/ivy/ant/antlib.xml">
        <classpath>
            <pathelement location="${ivy.jar.file}"/>
        </classpath>
    </taskdef>

    <!-- define your destination directory here -->
    <retrieve pattern="${lib-ivy.dir}/[type]/[artifact]-[revision].[ext]" sync="true">
        <!-- Add all your maven dependencies here -->
        <dependency org="com.twelvemonkeys.imageio" name="imageio-jpeg" rev="3.4.2"/>
        <dependency org="com.twelvemonkeys.imageio" name="imageio-tiff" rev="3.4.2"/>
    </retrieve>
</target>

注意:在之前创建常春藤图书馆目录。在本例中,您至少应该有一个名为
libant
的目录


希望它有帮助:o)

您可以使用ant
添加依赖项,或者您可以使用类似apache ivy的工具。使用maven,我可以从maven repository添加依赖项。使用ant tool是否可行。使用ivy,您可以使用maven repository。看到关于这个错误的任何想法。。D:\jijesh\workspace\Demo\build.xml:4:问题:无法创建任务或类型antlib:org.apache.ivy.ant:解析原因:名称未定义。措施:检查拼写。操作:检查是否已声明任何自定义任务/类型。措施:检查是否发生了任何/声明。此命名空间中未定义任何类型或任务yet@jijeshAj蚂蚁找不到常春藤罐子了。这就是我的“安装常春藤”目标的目的。如果ivy类不存在,它会自动下载。我已经下载并复制到ant/bin和users/.ant/lib文件夹。仍然显示错误。@jijeshAj ant/bin不好。需要是$antu HOME/lib。或者$HOME/.ant/lib。再次尝试运行我上面提供的“安装ivy”任务。Ivy和任何其他ANT扩展一样,它的jar必须位于ANT可以在Startup上找到的位置。这里的代码示例使用Ivy版本2.3.0。如果您今天使用该版本,可能会出现错误,“服务器错误:需要HTTPS”。
resolve:
[ivy:cachepath] :: Apache Ivy 2.3.0 - 20130110142753 :: http://ant.apache.org/ivy/ ::
[ivy:cachepath] :: loading settings :: url = jar:file:/home/mark/.ant/lib/ivy.jar!/org/apache/ivy/core/settings/ivysettings.xml
[ivy:cachepath] :: resolving dependencies :: #;working@mark
[ivy:cachepath]     confs: [default]
[ivy:cachepath]     found org.hibernate#hibernate;3.2.7.ga in public
[ivy:cachepath]     found net.sf.ehcache#ehcache;1.2.3 in public
[ivy:cachepath]     found commons-logging#commons-logging;1.0.4 in public
[ivy:cachepath]     found asm#asm-attrs;1.5.3 in public
[ivy:cachepath]     found dom4j#dom4j;1.6.1 in public
[ivy:cachepath]     found antlr#antlr;2.7.6 in public
[ivy:cachepath]     found cglib#cglib;2.1_3 in public
[ivy:cachepath]     found asm#asm;1.5.3 in public
[ivy:cachepath]     found commons-collections#commons-collections;2.1.1 in public
[ivy:cachepath] :: resolution report :: resolve 373ms :: artifacts dl 10ms
[ivy:cachepath]     :: evicted modules:
[ivy:cachepath]     commons-collections#commons-collections;2.1 by [commons-collections#commons-collections;2.1.1] in [default]
    ---------------------------------------------------------------------
    |                  |            modules            ||   artifacts   |
    |       conf       | number| search|dwnlded|evicted|| number|dwnlded|
    ---------------------------------------------------------------------
    |      default     |   10  |   0   |   0   |   1   ||   9   |   0   |
    ---------------------------------------------------------------------
<javac includeantruntime="false" srcdir="./src" destdir="staging" classpathref="compile.path"/>
<target name="update-lib-dir">
    <property name="ivy.install.version" value="2.4.0"/>
    <property name="ivy.jar.file" value="lib-ant/ivy-${ivy.install.version}.jar"/>
    <property name="lib-ivy.dir" value="lib-ivy"/>
    <get src="https://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar"
        dest="${ivy.jar.file}" usetimestamp="true" />

    <taskdef resource="org/apache/ivy/ant/antlib.xml">
        <classpath>
            <pathelement location="${ivy.jar.file}"/>
        </classpath>
    </taskdef>

    <!-- define your destination directory here -->
    <retrieve pattern="${lib-ivy.dir}/[type]/[artifact]-[revision].[ext]" sync="true">
        <!-- Add all your maven dependencies here -->
        <dependency org="com.twelvemonkeys.imageio" name="imageio-jpeg" rev="3.4.2"/>
        <dependency org="com.twelvemonkeys.imageio" name="imageio-tiff" rev="3.4.2"/>
    </retrieve>
</target>