简体   繁体   English

Java Ant,从repo获取Ivy时出错

[英]Java Ant, error getting Ivy from repo

I am trying to use ant + ivy together. 我试图一起使用ant +常春藤。

This is what I have done so far. 这就是我到目前为止所做的。 I have just the ant file build.xml, which I edited, to download ivy jar file. 我只有我编辑的ant文件build.xml来下载ivy jar文件。

<?xml version="1.0"?>

<project name="spring" basedir="." default="usage" xmlns:ivy="antlib:org.apache.ivy.ant" >
    <property file="build.properties"/>

    <property name="src.dir" value="src"/>
    <property name="web.dir" value="war"/>
    <property name="build.dir" value="${web.dir}/WEB-INF/classes"/>
    <property name="name" value="ivy"/>


    <path id="master-classpath">
        <fileset dir="${web.dir}/WEB-INF/lib">
            <include name="*.jar"/>
        </fileset>
        <!-- We need the servlet API classes: -->
        <!--  * for Tomcat 5/6 use servlet-api.jar -->
        <!--  * for other app servers - check the docs -->
        <fileset dir="${appserver.lib}">
            <include name="servlet*.jar"/>
        </fileset>
        <pathelement path="${build.dir}"/>
    </path>

    <target name="usage">
        <echo message=""/>
        <echo message="${name} build file"/>
        <echo message="-----------------------------------"/>
        <echo message=""/>
        <echo message="Available targets are:"/>
        <echo message=""/>
        <echo message="build     --> Build the application"/>
        <echo message="deploy    --> Deploy application as directory"/>
        <echo message="deploywar --> Deploy application as a WAR file"/>
        <echo message="install   --> Install application in Tomcat"/>
        <echo message="reload    --> Reload application in Tomcat"/>
        <echo message="start     --> Start Tomcat application"/>
        <echo message="stop      --> Stop Tomcat application"/>
        <echo message="list      --> List Tomcat applications"/>
        <echo message=""/>
    </target>

    <target name="build" description="Compile main source tree java files">
        <mkdir dir="${build.dir}"/>
        <javac destdir="${build.dir}" source="1.5" target="1.5" debug="true"
               deprecation="false" optimize="false" failonerror="true" includeantruntime="false">
            <src path="${src.dir}"/>
            <classpath refid="master-classpath"/>
        </javac>
    </target>

    <target name="deploy" depends="build" description="Deploy application">
        <copy todir="${deploy.path}/${name}" preservelastmodified="true">
            <fileset dir="${web.dir}">
                <include name="**/*.*"/>
            </fileset>
        </copy>
    </target>

    <target name="deploywar" depends="build" description="Deploy application as a WAR file">
        <war destfile="${name}.war"
             webxml="${web.dir}/WEB-INF/web.xml">
            <fileset dir="${web.dir}">
                <include name="**/*.*"/>
            </fileset>
        </war>
        <copy todir="${deploy.path}" preservelastmodified="true">
            <fileset dir=".">
                <include name="${name}.war"/>
            </fileset>
        </copy>
    </target>

    <target name="clean" description="Clean output directories">
        <delete>
            <fileset dir="${build.dir}">
                <include name="**/*.class"/>
            </fileset>
        </delete>
    </target>

<!-- ============================================================== -->
<!-- Tomcat tasks - remove these if you don't have Tomcat installed -->
<!-- ============================================================== -->

    <path id="catalina-ant-classpath">
        <!-- We need the Catalina jars for Tomcat -->
        <!--  * for other app servers - check the docs -->
        <fileset dir="${appserver.lib}">
            <include name="catalina-ant.jar"/>
        </fileset>
    </path>

    <taskdef name="install" classname="org.apache.catalina.ant.DeployTask">
        <classpath refid="catalina-ant-classpath"/>
    </taskdef>
    <taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask">
        <classpath refid="catalina-ant-classpath"/>
    </taskdef>
    <taskdef name="list" classname="org.apache.catalina.ant.ListTask">
        <classpath refid="catalina-ant-classpath"/>
    </taskdef>
    <taskdef name="start" classname="org.apache.catalina.ant.StartTask">
        <classpath refid="catalina-ant-classpath"/>
    </taskdef>
    <taskdef name="stop" classname="org.apache.catalina.ant.StopTask">
        <classpath refid="catalina-ant-classpath"/>
    </taskdef>

    <target name="install" description="Install application in Tomcat">
        <install url="${tomcat.manager.url}"
                 username="${tomcat.manager.username}"
                 password="${tomcat.manager.password}"
                 path="/${name}"
                 war="${name}"/>
    </target>

    <target name="reload" description="Reload application in Tomcat">
        <reload url="${tomcat.manager.url}"
                 username="${tomcat.manager.username}"
                 password="${tomcat.manager.password}"
                 path="/${name}"/>
    </target>

    <target name="start" description="Start Tomcat application">
        <start url="${tomcat.manager.url}"
                 username="${tomcat.manager.username}"
                 password="${tomcat.manager.password}"
                 path="/${name}"/>
    </target>

    <target name="stop" description="Stop Tomcat application">
        <stop url="${tomcat.manager.url}"
                 username="${tomcat.manager.username}"
                 password="${tomcat.manager.password}"
                 path="/${name}"/>
    </target>

    <target name="list" description="List Tomcat applications">
        <list url="${tomcat.manager.url}"
                 username="${tomcat.manager.username}"
                 password="${tomcat.manager.password}"/>
    </target>

<!-- End Tomcat tasks -->

<!-- Ivy settings start-->

    <target name="-download-ivy" unless="skip.download">
        <!-- download Ivy from web site so that it can be used even without any special installation -->
        <echo message="installing ivy..."/>
        <get src="http://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar"
             dest="${ivy.jar.file}" usetimestamp="true"/>
    </target>


<!-- Ivy settings end-->

</project>

This is my build.properties: 这是我的build.properties:

# Ant properties for building the springapp

appserver.home=C:/apache-tomcat-7.0.20
# for Tomcat 5 use $appserver.home}/server/lib
# for Tomcat 6 use $appserver.home}/lib
appserver.lib=C:/apache-tomcat-7.0.20/lib

deploy.path=C:/apache-tomcat-7.0.20/webapps

tomcat.manager.url=http://localhost:8080/manager
tomcat.manager.username=tomcat
tomcat.manager.password=s3cret



ivy.install.version=2.2.0
ivy.jar.file=${lib.build.dir}/ivy-${ivy.install.version}.jar

When I try to deploy my war file and -download-ivy with ant, I get following error in eclipse: 当我尝试使用ant部署我的war文件和-download-ivy时,我在eclipse中遇到以下错误:

Buildfile: C:\Users\Jansu\workspace\HelloWorld\build.xml
build:
deploywar:
-download-ivy:
     [echo] installing ivy...
      [get] Getting: http://repo1.maven.org/maven2/org/apache/ivy/ivy/2.2.0/ivy-2.2.0.jar
      [get] To: C:\Users\Jansu\workspace\HelloWorld\${lib.build.dir}\ivy-2.2.0.jar
      [get] Error getting http://repo1.maven.org/maven2/org/apache/ivy/ivy/2.2.0/ivy-2.2.0.jar to C:\Users\Jansu\workspace\HelloWorld\${lib.build.dir}\ivy-2.2.0.jar

BUILD FAILED
C:\Users\Jansu\workspace\HelloWorld\build.xml:153: java.io.FileNotFoundException: C:\Users\Jansu\workspace\HelloWorld\${lib.build.dir}\ivy-2.2.0.jar (The system cannot find the path specified)

Total time: 1 second

What could be the problem? 可能是什么问题呢? The address http://repo1.maven.org/maven2/org/apache/ivy/ivy/2.2.0/ivy-2.2.0.jar exists, I could download from there manually. 地址http://repo1.maven.org/maven2/org/apache/ivy/ivy/2.2.0/ivy-2.2.0.jar存在,我可以从那里手动下载。

According to the log, the problem is that lib.build.dir definition is missing in your build.properties file. 根据日志,问题是build.properties文件中缺少lib.build.dir定义。 So in order to fix this problem, you should : 所以为了解决这个问题,你应该:

  • add the definition of lib.build.dir in your build.properties , build.properties添加lib.build.dir的定义,
  • create this dir at the beginning of the -download-ivy target ( <mkdir dir="${lib.build.dir}" /> ). -download-ivy目标( <mkdir dir="${lib.build.dir}" /> )的开头创建这个目录。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM