草庐IT

ant - 如何在命令行中执行 Ant build

coder 2023-04-24 原文

我有一个 Ant 构建文件,我尝试使用以下命令在命令行中执行它:

$ C:\Program Files (x86)\.....>ant -f C:\Silk4J\Automation\iControlSilk4J\build.xml

但是什么也没发生,结果是:
BUILD SUCCESSFUL
Total time: 0 seconds

我的环境变量是正确的。

问题是什么?这是我的构建文件:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- WARNING: Eclipse auto-generated file.
              Any modifications will be overwritten.
              To include a user specific buildfile here, simply create one in the same
              directory with the processing instruction <?eclipse.ant.import?>
              as the first entry and export the buildfile again. -->
<project basedir="." default="build" name="iControlSilk4J">
    <property environment="env"/>
    <property name="ECLIPSE_HOME" value="../../../Program Files (x86)/Silk/SilkTest/eclipse"/>
    <property name="junit.output.dir" value="junit"/>
    <property name="debuglevel" value="source,lines,vars"/>
    <property name="target" value="1.6"/>
    <property name="source" value="1.6"/>
    <path id="Silk Test JTF 13.5.0 Library.libraryclasspath">
        <pathelement location="../../../Program Files (x86)/Silk/SilkTest/ng/JTF/silktest-jtf-nodeps.jar"/>
    </path>
    <path id="JUnit 4.libraryclasspath">
        <pathelement location="${ECLIPSE_HOME}/plugins/org.junit_4.8.2.v4_8_2_v20110321-1705/junit.jar"/>
        <pathelement location="${ECLIPSE_HOME}/plugins/org.hamcrest.core_1.1.0.v20090501071000.jar"/>
    </path>
    <path id="iControlSilk4J.classpath">
        <pathelement location="bin"/>
        <pathelement location="lib/apache-log4j.jar"/>
        <pathelement location="lib/commons-io-2.4.jar"/>
        <pathelement location="lib/commons-lang3-3.1.jar"/>
        <pathelement location="lib/junit.jar"/>
        <pathelement location="lib/org.hamcrest.core_1.1.0.v20090501071000.jar"/>
        <pathelement location="lib/silktest-jtf-nodeps.jar"/>
        <path refid="Silk Test JTF 13.5.0 Library.libraryclasspath"/>
        <path refid="JUnit 4.libraryclasspath"/>
        <pathelement location="../../../Users/Admin/Desktop/java-mail-1.4.4.jar"/>
        <pathelement location="../../../Users/Admin/Desktop/javax.activation.jar"/>
        <pathelement location="lib/joda-time-2.3.jar"/>
    </path>
    <target name="init">
        <mkdir dir="bin"/>
        <copy includeemptydirs="false" todir="bin">
            <fileset dir="src">
                <exclude name="**/*.java"/>
            </fileset>
        </copy>
    </target>
    <target name="clean">
        <delete dir="bin"/>
    </target>
    <target depends="clean" name="cleanall"/>
    <target depends="build-subprojects,build-project" name="build"/>
    <target name="build-subprojects"/>
    <target depends="init" name="build-project">
        <echo message="${ant.project.name}: ${ant.file}"/>
        <javac debug="true" debuglevel="${debuglevel}" destdir="bin" source="${source}" target="${target}">
            <src path="src"/>
            <classpath refid="iControlSilk4J.classpath"/>
        </javac>
    </target>
    <target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects"/>
    <target description="copy Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler">
        <copy todir="${ant.library.dir}">
            <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
        </copy>
        <unzip dest="${ant.library.dir}">
            <patternset includes="jdtCompilerAdapter.jar"/>
            <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
        </unzip>
    </target>
    <target description="compile project with Eclipse compiler" name="build-eclipse-compiler">
        <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
        <antcall target="build"/>

...

最佳答案

转到 Ant 网站和 download .这样,您就有了 Eclipse 之外的 Ant 副本。我建议把它放在 C:\ant 下目录。这样,目录名称中就没有任何空格。在您的系统控制面板中,设置环境变量 ANT_HOME到这个目录,然后预挂到系统 PATH变量,%ANT_HOME%\bin .这样,您不必输入整个目录名称。

假设您执行了上述操作,请尝试以下操作:

C:\> cd \Silk4J\Automation\iControlSilk4J
C:\Silk4J\Automation\iControlSilk4J> ant -d build

这将做几件事:
  • 它将消除问题出在 Eclipe 版本的 Ant 上的可能性。
  • 输入
  • 更容易
  • 由于您正在执行 build.xml在它存在的目录中,您最终不会遇到 Ant 构建无法定位特定目录的可能性。
  • -d将打印出大量输出,因此您可能想要捕获它,或者将终端缓冲区设置为类似 99999 的内容。 ,然后运行 ​​cls首先清除缓冲区。这样,您将在终端缓冲区中从头开始捕获所有输出。

    让我们看看 Ant 应该如何执行。您没有指定要执行的任何目标,因此 Ant 应该采用默认值 build目标。这里是:
    <target depends="build-subprojects,build-project" name="build"/>
    
    build目标本身什么都不做。但是,它取决于另外两个目标,因此将首先调用它们:

    第一个目标是 build-subprojects :
    <target name="build-subprojects"/>
    

    这根本没有任何作用。它甚至没有依赖关系。

    指定的下一个目标是 build-project确实有代码:
    <target depends="init" name="build-project">
    

    此目标确实包含任务,一些依赖目标。之前 build-project执行,它将首先运行 init目标:
    <target name="init">
        <mkdir dir="bin"/>
        <copy includeemptydirs="false" todir="bin">
            <fileset dir="src">
                <exclude name="**/*.java"/>
            </fileset>
        </copy>
    </target>
    

    该目标创建了一个名为 bin 的目录。 ,然后复制 src 下的所有文件带有后缀的树 *.java转至 bin目录。 includeemptydirs意味着不会创建没有非 java 代码的目录。

    Ant 使用一种方案来完成最少的工作。例如,如果 bin创建目录后,<mkdir/>任务没有执行。此外,如果之前复制了一个文件,或者您的 src 中没有非 Java 文件。目录树,<copy/>任务不会运行。然而,init目标仍将被执行。

    接下来,我们回到我们之前的build-project目标:
    <target depends="init" name="build-project">
        <echo message="${ant.project.name}: ${ant.file}"/>
        <javac debug="true" debuglevel="${debuglevel}" destdir="bin" source="${source}" target="${target}">
            <src path="src"/>
            <classpath refid="iControlSilk4J.classpath"/>
        </javac>
    </target>
    

    看看这一行:
    <echo message="${ant.project.name}: ${ant.file}"/>
    

    那应该一直执行。您的输出是否打印:
    [echo] iControlSilk4J: C:\Silk4J\Automation\iControlSilk4J\build.xml
    

    也许你没有意识到这是来自你的构建。

    之后,它运行 <javac/>任务。也就是说,如果有任何文件要实际编译。同样,Ant 试图避免它不必做的工作。如果所有的*.java文件之前已经编译过,<javac/>任务不会执行。

    而且,这就是构建的结束。您的构建可能仅仅因为无事可做而没有做任何事情。您可以尝试运行 clean任务,然后 build :
    C:\Silk4J\Automation\iControlSilk4J> ant -d clean build
    

    但是,Ant 通常会打印正在执行的目标。你应该见过这个:
    init:
    
    build-subprojects:
    
    build-projects:
    
        [echo] iControlSilk4J: C:\Silk4J\Automation\iControlSilk4J\build.xml
    
    build:
    
    Build Successful
    

    请注意,所有目标都是按照执行顺序打印出来的,而任务是在执行时打印出来的。但是,如果没有要编译的内容,或者没有要复制的内容,那么您将看不到这些任务正在执行。这看起来像你的输出吗?如果是这样,那可能没什么可做的。
  • 如果bin目录已存在,<mkdir/>不会执行。
  • 如果src中没有非Java文件,或者它们已经被复制到 bin , <copy/>任务不会执行。
  • 如果您的 src 中没有 Java 文件目录,或者它们已经被编译,<java/>任务不会运行。

  • 如果您查看 -d 的输出调试,您将看到 Ant 在查看任务,然后解释为什么没有执行特定任务。另外,调试选项将解释 Ant 如何决定要执行的任务。

    看看是否有帮助。

    关于ant - 如何在命令行中执行 Ant build,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19038279/

    有关ant - 如何在命令行中执行 Ant build的更多相关文章

    1. ruby - 如何在 Ruby 中顺序创建 PI - 2

      出于纯粹的兴趣,我很好奇如何按顺序创建PI,而不是在过程结果之后生成数字,而是让数字在过程本身生成时显示。如果是这种情况,那么数字可以自行产生,我可以对以前看到的数字实现垃圾收集,从而创建一个无限系列。结果只是在Pi系列之后每秒生成一个数字。这是我通过互联网筛选的结果:这是流行的计算机友好算法,类机器算法:defarccot(x,unity)xpow=unity/xn=1sign=1sum=0loopdoterm=xpow/nbreakifterm==0sum+=sign*(xpow/n)xpow/=x*xn+=2sign=-signendsumenddefcalc_pi(digits

    2. ruby-openid:执行发现时未设置@socket - 2

      我在使用omniauth/openid时遇到了一些麻烦。在尝试进行身份验证时,我在日志中发现了这一点:OpenID::FetchingError:Errorfetchinghttps://www.google.com/accounts/o8/.well-known/host-meta?hd=profiles.google.com%2Fmy_username:undefinedmethod`io'fornil:NilClass重要的是undefinedmethodio'fornil:NilClass来自openid/fetchers.rb,在下面的代码片段中:moduleNetclass

    3. ruby - 如何在 buildr 项目中使用 Ruby 代码? - 2

      如何在buildr项目中使用Ruby?我在很多不同的项目中使用过Ruby、JRuby、Java和Clojure。我目前正在使用我的标准Ruby开发一个模拟应用程序,我想尝试使用Clojure后端(我确实喜欢功能代码)以及JRubygui和测试套件。我还可以看到在未来的不同项目中使用Scala作为后端。我想我要为我的项目尝试一下buildr(http://buildr.apache.org/),但我注意到buildr似乎没有设置为在项目中使用JRuby代码本身!这看起来有点傻,因为该工具旨在统一通用的JVM语言并且是在ruby中构建的。除了将输出的jar包含在一个独特的、仅限ruby​​

    4. ruby - 什么是填充的 Base64 编码字符串以及如何在 ruby​​ 中生成它们? - 2

      我正在使用的第三方API的文档状态:"[O]urAPIonlyacceptspaddedBase64encodedstrings."什么是“填充的Base64编码字符串”以及如何在Ruby中生成它们。下面的代码是我第一次尝试创建转换为Base64的JSON格式数据。xa=Base64.encode64(a.to_json) 最佳答案 他们说的padding其实就是Base64本身的一部分。它是末尾的“=”和“==”。Base64将3个字节的数据包编码为4个编码字符。所以如果你的输入数据有长度n和n%3=1=>"=="末尾用于填充n%

    5. ruby - 在 Ruby 中编写命令行实用程序 - 2

      我想用ruby​​编写一个小的命令行实用程序并将其作为gem分发。我知道安装后,Guard、Sass和Thor等某些gem可以从命令行自行运行。为了让gem像二进制文件一样可用,我需要在我的gemspec中指定什么。 最佳答案 Gem::Specification.newdo|s|...s.executable='name_of_executable'...endhttp://docs.rubygems.org/read/chapter/20 关于ruby-在Ruby中编写命令行实用程序

    6. ruby-on-rails - 如何在 ruby​​ 中使用两个参数异步运行 exe? - 2

      exe应该在我打开页面时运行。异步进程需要运行。有什么方法可以在ruby​​中使用两个参数异步运行exe吗?我已经尝试过ruby​​命令-system()、exec()但它正在等待过程完成。我需要用参数启动exe,无需等待进程完成是否有任何ruby​​gems会支持我的问题? 最佳答案 您可以使用Process.spawn和Process.wait2:pid=Process.spawn'your.exe','--option'#Later...pid,status=Process.wait2pid您的程序将作为解释器的子进程执行。除

    7. ruby - 如何在续集中重新加载表模式? - 2

      鉴于我有以下迁移:Sequel.migrationdoupdoalter_table:usersdoadd_column:is_admin,:default=>falseend#SequelrunsaDESCRIBEtablestatement,whenthemodelisloaded.#Atthispoint,itdoesnotknowthatusershaveais_adminflag.#Soitfails.@user=User.find(:email=>"admin@fancy-startup.example")@user.is_admin=true@user.save!ende

    8. ruby - 如何在 Ruby 中拆分参数字符串 Bash 样式? - 2

      我正在为一个项目制作一个简单的shell,我希望像在Bash中一样解析参数字符串。foobar"helloworld"fooz应该变成:["foo","bar","helloworld","fooz"]等等。到目前为止,我一直在使用CSV::parse_line,将列分隔符设置为""和.compact输出。问题是我现在必须选择是要支持单引号还是双引号。CSV不支持超过一个分隔符。Python有一个名为shlex的模块:>>>shlex.split("Test'helloworld'foo")['Test','helloworld','foo']>>>shlex.split('Test"

    9. ruby - 如何在 Lion 上安装 Xcode 4.6,需要用 RVM 升级 ruby - 2

      我实际上是在尝试使用RVM在我的OSX10.7.5上更新ruby,并在输入以下命令后:rvminstallruby我得到了以下回复:Searchingforbinaryrubies,thismighttakesometime.Checkingrequirementsforosx.Installingrequirementsforosx.Updatingsystem.......Errorrunning'requirements_osx_brew_update_systemruby-2.0.0-p247',pleaseread/Users/username/.rvm/log/138121

    10. ruby - Chef 执行非顺序配方 - 2

      我遵循了教程http://gettingstartedwithchef.com/,第1章。我的运行list是"run_list":["recipe[apt]","recipe[phpap]"]我的phpapRecipe默认Recipeinclude_recipe"apache2"include_recipe"build-essential"include_recipe"openssl"include_recipe"mysql::client"include_recipe"mysql::server"include_recipe"php"include_recipe"php::modul

    随机推荐