Category Archives: ant

Ant ‘if’ with ‘equals’ doesn’t seem to be working

I'm running an Ant target in a Salesforce build.xml file. The target contains a task that loops through a list of strings separated by line endings in a .txt file (the 'metadata.types' variable in the code below references the .txt file, and I'm on Windows.)

One of the metatdata types in the list is 'CustomObject', so it should trigger the 'Sorting @{metadataType} buffer' echo statement below. However, it doesn't; it just skips through to the "i am at @{metadataType}" echo statement and prints out 'i am at CustomObject'.

What am I missing?

<for param="metadataType" list="${metadata.types}" delimiter="${line.separator}">
    <sequential>
        <local name="type"/>
        <echo level="warning" message="Hello @{metadataType}"/>
        <if>
            <equals arg1="@{metadataType}" arg2="CustomObject" />
            <then>
                <echo level="info" message="Sorting @{metadataType} buffer"/>
            </then>
            <else>
                <if>
                    <not>
                        <equals arg1="@{metadataType}" arg2=""/>
                    </not>
                    <then>
                        <echo level="warning" message="i am at @{metadataType}"/>
                        <xmltask sourcebuffer="pkgbuff" destbuffer="pkgbuff">
                            <insert path="/*[local-name()='Package']"><![CDATA[
                                <types>
                                    <name>@{metadataType}</name>
                                    <members>*</members>
                                </types> ]]>
                            </insert>
                        </xmltask>
                    </then>
                </if>
            </else>
        </if>
    </sequential>
</for>

Is chmodding ANT and Tomcat src directories unsafe?

I had some difficulty using Ant to build Tomcat getting the following error (in Linux Mint 18 -- it seems a lot of these questions are geared to Windows):

unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK

It went on to tell me that JAVA_HOME pointed to the JRE, when I had already configured ~/.bashrc to point elsewhere. I checked ~/.bash_profile and /etc/profile as well just to check and make sure my variable wasn't being overwritten elsewhere (I've read the .bashrc vs. .bash_profile vs. etc/profile answers a few times now and am admittedly slow to understand).

The "fix" came down to running chmod 0777 on my Ant and Tomcat source directories, and running Ant as myself, and not sudo. I'm currently the only user on this machine, but I'm curious as to how insecure I've made this build. Is there a better way to do this, or did I just hack something now, only to pay for it later?

Making directory with ANT build.xml throws error creation wasn’t successful for unknown reason

I'm trying to create a directory with the lastmodified timestamp of a file,but while creating a directory with this timestamp it throws error,

<macrodef name="getFileTimes">
    <attribute name="dir" />
    <attribute name="file" />
    <attribute name="setprop" default="@{file}_ctime" />
    <sequential>
      <exec executable="cmd" dir="@{dir}" outputproperty="@{setprop}">
        <arg value="/c" />
        <arg line="dir @{file} |find ' @{file}'" />
      </exec>
      <script language="javascript">
        tmp = project.getProperty("@{setprop}").split(" ");
        project.setProperty("@{setprop}", tmp[0]+"_"+tmp[2]) ;
   </script>
    </sequential>
  </macrodef>

  <getFileTimes dir="${Results.dir}" file="Log.log" />

              <echo>
              $${filemodified_ctime} => ${Log.log_ctime}
              </echo>

<mkdir dir="${basedir}/Reports/${Log.log_ctime}"/>

Error: creation wasn't successful for unknown reason

but instead of ${Log.log_ctime} if I use ${timestamp} it is able to create a folder with the current timestamp, but I need the folder to be created with the time that was captured.

Get the timestamp of a folder using ANT build.xml

Trying to get the timestamp of a results folder and print it, but unfortunately the following code is not working properly,

<property name="timestamponresults" value="${dir}/Results"/> 
           <a:fileutil file="${timestamponresults}" property="results_date"> 
               <a:lastmodified format="yyyy-MM-dd"/> 
           </a:fileutil> 
    <echo message="timestamp on results folder is ${results_date}"</echo> 

it shows the following error, The prefix "a" for element "a:fileutil" is not bound,Please suggest if there are any other alternatives

Execute .jardesc and start build.xml

Let's say I have this simple ant file which is executed every time I save a file in eclipse.

<?xml version="1.0"?>
   <project name="Hello World Project" default="compile">

   <target name="compile">
      <echo>Hello World - Welcome to Apache Ant!</echo>
   </target>

</project>

How do I change it so that it first executes a .jardesc file and then another build.xml file in the same project?

Trouble installing Ant 1.9.7

I'm trying to run this command in Windows (it is step 5 in these instructions) from Ant's home directory:

ant -f fetch.xml -Ddest=system

But I get the following error:

init:

logging:
[artifact:dependencies] Downloading: log4j/log4j/1.2.14/log4j-1.2.14.pom
[artifact:dependencies] Transferring 2K
[artifact:dependencies] Downloading: log4j/log4j/1.2.14/log4j-1.2.14.jar
[artifact:dependencies] Transferring 358K
     [copy] Copying 1 file to C:\Program Files\apache-ant-1.9.7\lib
[artifact:dependencies] Downloading: commons-logging/commons-logging-api/1.1/commons-logging-api-1.1.pom
[artifact:dependencies] Transferring 5K
[artifact:dependencies] Downloading: commons-logging/commons-logging-api/1.1/commons-logging-api-1.1.jar
[artifact:dependencies] Transferring 43K
     [copy] Copying 1 file to C:\Program Files\apache-ant-1.9.7\lib

junit:
[artifact:dependencies] Downloading: junit/junit/4.11/junit-4.11.pom
[artifact:dependencies] Transferring 2K
[artifact:dependencies] Downloading: org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.pom
[artifact:dependencies] Transferring 0K
[artifact:dependencies] Downloading: org/hamcrest/hamcrest-parent/1.3/hamcrest-parent-1.3.pom
[artifact:dependencies] Transferring 1K
[artifact:dependencies] Downloading: org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar
[artifact:dependencies] Transferring 43K
[artifact:dependencies] Downloading: junit/junit/4.11/junit-4.11.jar
[artifact:dependencies] Transferring 239K
     [copy] Copying 2 files to C:\Program Files\apache-ant-1.9.7\lib

xml:
[artifact:dependencies] Downloading: xalan/xalan/2.7.1/xalan-2.7.1.pom
[artifact:dependencies] Transferring 1K
[artifact:dependencies] Downloading: xalan/serializer/2.7.1/serializer-2.7.1.pom

[artifact:dependencies] Transferring 1K
[artifact:dependencies] Downloading: xml-apis/xml-apis/1.3.04/xml-apis-1.3.04.pom
[artifact:dependencies] Transferring 1K
[artifact:dependencies] Downloading: xalan/serializer/2.7.1/serializer-2.7.1.jar

[artifact:dependencies] Transferring 271K
[artifact:dependencies] Downloading: xml-apis/xml-apis/1.3.04/xml-apis-1.3.04.jar
[artifact:dependencies] Transferring 189K
[artifact:dependencies] Downloading: xalan/xalan/2.7.1/xalan-2.7.1.jar
[artifact:dependencies] Transferring 3101K
     [copy] Copying 3 files to C:\Program Files\apache-ant-1.9.7\lib
[artifact:dependencies] Downloading: xml-resolver/xml-resolver/1.2/xml-resolver-1.2.pom
[artifact:dependencies] Transferring 1K
[artifact:dependencies] Downloading: xml-resolver/xml-resolver/1.2/xml-resolver-1.2.jar
[artifact:dependencies] Transferring 82K
     [copy] Copying 1 file to C:\Program Files\apache-ant-1.9.7\lib

networking:
[artifact:dependencies] Downloading: commons-net/commons-net/1.4.1/commons-net-1.4.1.pom
[artifact:dependencies] Transferring 4K
[artifact:dependencies] Downloading: oro/oro/2.0.8/oro-2.0.8.pom
[artifact:dependencies] Transferring 0K
[artifact:dependencies] Downloading: commons-net/commons-net/1.4.1/commons-net-1.4.1.jar
[artifact:dependencies] Transferring 176K
[artifact:dependencies] Downloading: oro/oro/2.0.8/oro-2.0.8.jar
[artifact:dependencies] Transferring 63K
     [copy] Copying 2 files to C:\Program Files\apache-ant-1.9.7\lib
[artifact:dependencies] Downloading: com/jcraft/jsch/0.1.50/jsch-0.1.50.pom
[artifact:dependencies] Transferring 3K
[artifact:dependencies] Downloading: org/sonatype/oss/oss-parent/6/oss-parent-6.pom
[artifact:dependencies] Transferring 4K
[artifact:dependencies] Downloading: com/jcraft/jsch/0.1.50/jsch-0.1.50.jar
[artifact:dependencies] Transferring 248K
     [copy] Copying 1 file to C:\Program Files\apache-ant-1.9.7\lib

regexp:
[artifact:dependencies] Downloading: regexp/regexp/1.3/regexp-1.3.pom
[artifact:dependencies] Transferring 0K
[artifact:dependencies] Downloading: regexp/regexp/1.3/regexp-1.3.jar
[artifact:dependencies] Transferring 24K
     [copy] Copying 1 file to C:\Program Files\apache-ant-1.9.7\lib

antlr:
[artifact:dependencies] Downloading: antlr/antlr/2.7.7/antlr-2.7.7.pom
[artifact:dependencies] Transferring 0K
[artifact:dependencies] Downloading: antlr/antlr/2.7.7/antlr-2.7.7.jar
[artifact:dependencies] Transferring 434K
     [copy] Copying 1 file to C:\Program Files\apache-ant-1.9.7\lib

bcel:
[artifact:dependencies] Downloading: bcel/bcel/5.1/bcel-5.1.pom
[artifact:dependencies] Transferring 0K
[artifact:dependencies] Downloading: regexp/regexp/1.2/regexp-1.2.pom
[artifact:dependencies] Transferring 0K
[artifact:dependencies] Downloading: regexp/regexp/1.2/regexp-1.2.jar
[artifact:dependencies] Transferring 29K
[artifact:dependencies] Downloading: bcel/bcel/5.1/bcel-5.1.jar
[artifact:dependencies] Transferring 503K
     [copy] Copying 2 files to C:\Program Files\apache-ant-1.9.7\lib

jdepend:
[artifact:dependencies] Downloading: jdepend/jdepend/2.9.1/jdepend-2.9.1.pom
[artifact:dependencies] Transferring 0K
[artifact:dependencies] Downloading: jdepend/jdepend/2.9.1/jdepend-2.9.1.jar
[artifact:dependencies] Transferring 56K
     [copy] Copying 1 file to C:\Program Files\apache-ant-1.9.7\lib

bsf:
[artifact:dependencies] Downloading: bsf/bsf/2.4.0/bsf-2.4.0.pom
[artifact:dependencies] Transferring 1K
[artifact:dependencies] Downloading: commons-logging/commons-logging/1.0.4/commons-logging-1.0.4.pom
[artifact:dependencies] Transferring 5K
[artifact:dependencies] Downloading: commons-logging/commons-logging/1.0.4/commons-logging-1.0.4.jar
[artifact:dependencies] Transferring 37K
[artifact:dependencies] Downloading: bsf/bsf/2.4.0/bsf-2.4.0.jar
[artifact:dependencies] Transferring 110K
     [copy] Copying 2 files to C:\Program Files\apache-ant-1.9.7\lib

debugging:
[artifact:dependencies] Downloading: which/which/1.0/which-1.0.pom
[artifact:dependencies] Transferring 0K
[artifact:dependencies] Downloading: which/which/1.0/which-1.0.jar
[artifact:dependencies] Transferring 16K
     [copy] Copying 1 file to C:\Program Files\apache-ant-1.9.7\lib

jruby:
[artifact:dependencies] Downloading: org/jruby/jruby/0.9.8/jruby-0.9.8.pom
[artifact:dependencies] Transferring 5K
[artifact:dependencies] Downloading: org/jruby/shared/0.9.8/shared-0.9.8.pom
[artifact:dependencies] Transferring 4K
[artifact:dependencies] Downloading: asm/asm-commons/2.2.3/asm-commons-2.2.3.pom

[artifact:dependencies] Transferring 0K
[artifact:dependencies] Downloading: asm/asm-parent/2.2.3/asm-parent-2.2.3.pom
[artifact:dependencies] Transferring 2K
[artifact:dependencies] Downloading: asm/asm-tree/2.2.3/asm-tree-2.2.3.pom
[artifact:dependencies] Transferring 0K
[artifact:dependencies] Downloading: asm/asm/2.2.3/asm-2.2.3.pom
[artifact:dependencies] Transferring 0K
[artifact:dependencies] Downloading: asm/asm/2.2.3/asm-2.2.3.jar
[artifact:dependencies] Transferring 34K
[artifact:dependencies] Downloading: asm/asm-commons/2.2.3/asm-commons-2.2.3.jar

[artifact:dependencies] Transferring 14K
[artifact:dependencies] Downloading: org/jruby/jruby/0.9.8/jruby-0.9.8.jar
[artifact:dependencies] Transferring 1644K
[artifact:dependencies] Downloading: asm/asm-tree/2.2.3/asm-tree-2.2.3.jar
[artifact:dependencies] Transferring 15K
     [copy] Copying 4 files to C:\Program Files\apache-ant-1.9.7\lib

beanshell:
[artifact:dependencies] Downloading: org/beanshell/bsh/2.0b4/bsh-2.0b4.pom
[artifact:dependencies] Transferring 1K
[artifact:dependencies] Downloading: org/beanshell/beanshell/2.0b4/beanshell-2.0b4.pom
[artifact:dependencies] Transferring 1K
[artifact:dependencies] Downloading: org/beanshell/bsh/2.0b4/bsh-2.0b4.jar
[artifact:dependencies] Transferring 275K
     [copy] Copying 1 file to C:\Program Files\apache-ant-1.9.7\lib
[artifact:dependencies] Downloading: org/beanshell/bsh-core/2.0b4/bsh-core-2.0b4.pom
[artifact:dependencies] Transferring 0K
[artifact:dependencies] Downloading: org/beanshell/bsh-core/2.0b4/bsh-core-2.0b4.jar
[artifact:dependencies] Transferring 140K
     [copy] Copying 1 file to C:\Program Files\apache-ant-1.9.7\lib

rhino:
[artifact:dependencies] Downloading: rhino/js/1.6R7/js-1.6R7.pom
[artifact:dependencies] Transferring 0K
[artifact:dependencies] Downloading: rhino/js/1.6R7/js-1.6R7.jar
[artifact:dependencies] Transferring 794K
     [copy] Copying 1 file to C:\Program Files\apache-ant-1.9.7\lib

script:

javamail:
[artifact:dependencies] Downloading: javax/mail/mail/1.4/mail-1.4.pom
[artifact:dependencies] Transferring 0K
[artifact:dependencies] Downloading: javax/activation/activation/1.1/activation-1.1.pom
[artifact:dependencies] Transferring 1K
[artifact:dependencies] Downloading: javax/mail/mail/1.4/mail-1.4.jar
[artifact:dependencies] Transferring 379K
[artifact:dependencies] Downloading: javax/activation/activation/1.1/activation-1.1.jar
[artifact:dependencies] Transferring 61K
     [copy] Copying 2 files to C:\Program Files\apache-ant-1.9.7\lib

jspc:
[artifact:dependencies] Downloading: tomcat/jasper-compiler/4.1.36/jasper-compiler-4.1.36.pom
[artifact:dependencies] [WARNING] Unable to get resource from repository remote
(http://repo1.maven.org/maven2/)
[artifact:dependencies] Downloading: tomcat/jasper-compiler/4.1.36/jasper-compiler-4.1.36.pom
[artifact:dependencies] [WARNING] Unable to get resource from repository central
 (http://repo1.maven.org/maven2)
[artifact:dependencies] Downloading: tomcat/jasper-compiler/4.1.36/jasper-compiler-4.1.36.jar
[artifact:dependencies] Transferring 179K
     [copy] Copying 1 file to C:\Program Files\apache-ant-1.9.7\lib
[artifact:dependencies] Downloading: tomcat/jasper-runtime/4.1.36/jasper-runtime-4.1.36.pom
[artifact:dependencies] [WARNING] Unable to get resource from repository remote
(http://repo1.maven.org/maven2/)
[artifact:dependencies] Downloading: tomcat/jasper-runtime/4.1.36/jasper-runtime-4.1.36.pom
[artifact:dependencies] [WARNING] Unable to get resource from repository central
 (http://repo1.maven.org/maven2)
[artifact:dependencies] Downloading: tomcat/jasper-runtime/4.1.36/jasper-runtime-4.1.36.jar
[artifact:dependencies] Transferring 70K
     [copy] Copying 1 file to C:\Program Files\apache-ant-1.9.7\lib
[artifact:dependencies] Downloading: javax/servlet/servlet-api/2.3/servlet-api-2.3.pom
[artifact:dependencies] Transferring 0K
[artifact:dependencies] Downloading: javax/servlet/servlet-api/2.3/servlet-api-2.3.jar
[artifact:dependencies] Transferring 76K
     [copy] Copying 1 file to C:\Program Files\apache-ant-1.9.7\lib

jai:
[artifact:dependencies] Downloading: javax/media/jai-core/1.1.3/jai-core-1.1.3.pom
[artifact:dependencies] Transferring 1K
[artifact:dependencies] Downloading: javax/media/jai-core/1.1.3/jai-core-1.1.3.jar
[artifact:dependencies] Transferring 1856K
     [copy] Copying 1 file to C:\Program Files\apache-ant-1.9.7\lib
[artifact:dependencies] Downloading: com/sun/media/jai-codec/1.1.3/jai-codec-1.1.3.pom
[artifact:dependencies] Transferring 1K
[artifact:dependencies] Downloading: com/sun/media/jai-codec/1.1.3/jai-codec-1.1.3.jar
[artifact:dependencies] Transferring 252K
     [copy] Copying 1 file to C:\Program Files\apache-ant-1.9.7\lib

nonm2-macros:

init-no-m2:

init-cache:

-setup-temp-cache:
    [mkdir] Created dir: C:\Users\Mark\.ant\tempcache

-fetch-netrexx:

-fetch-netrexx-no-commons-net:
      [get] Getting: ftp://ftp.software.ibm.com/software/awdtools/netrexx/NetRexx.zip
      [get] To: C:\Users\Mark\.ant\tempcache\NetRexx.zip
      [get] Error getting ftp://ftp.software.ibm.com/software/awdtools/netrexx/NetRexx.zip to C:\Users\Mark\.ant\tempcache\NetRexx.zip

BUILD FAILED
C:\Program Files\apache-ant-1.9.7\fetch.xml:328: java.net.ConnectException: Connection timed out: connect
        at java.net.DualStackPlainSocketImpl.connect0(Native Method)
        at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
        at java.net.Socket.connect(Socket.java:589)
        at java.net.Socket.connect(Socket.java:538)
        at sun.net.ftp.impl.FtpClient.doConnect(FtpClient.java:957)
        at sun.net.ftp.impl.FtpClient.tryConnect(FtpClient.java:917)
        at sun.net.ftp.impl.FtpClient.connect(FtpClient.java:1012)
        at sun.net.ftp.impl.FtpClient.connect(FtpClient.java:998)
        at sun.net.www.protocol.ftp.FtpURLConnection.connect(FtpURLConnection.java:294)
        at org.apache.tools.ant.taskdefs.Get$GetThread.openConnection(Get.java:728)
        at org.apache.tools.ant.taskdefs.Get$GetThread.get(Get.java:641)
        at org.apache.tools.ant.taskdefs.Get$GetThread.run(Get.java:631)

Total time: 1 minute 15 seconds

I also tried to use the autoproxy flag with administrator rights, but I get the same error. What is wrong here?

When Run Ant Script, AspectJ does not Import Aspect source folder out side java classes?

I create simple Ant Script to compile my AspectJ Project. Java file compile well under <Javac> tag witch out compile using aspectJ. But when compiling Aspectj (.aj) file, it gives error not import java class. (`iajc - tag pass import error'). My aspect.aj file import some .java classes in other modules.

This is my build.xml file

  <target name="init"  >
     <!-- Create the build directory structure used by compile -->
     <mkdir dir="${build}/classes"/>
  </target>


  <target name="resolve" depends="init" >
     <!-- Compile the java code from ${src} into ${build}/classes -->
     <javac  srcdir="${src}" destdir="${build}/classes"  includeantruntime="false"  />
  </target>

  <taskdef resource="org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties">
    <classpath>
      <pathelement location="${lib}/aspectjtools-1.8.6.jar"/>
    </classpath>
  </taskdef>


  <target name="compile.aspectj"  depends = "resolve"  > 
     <iajc destDir="${build}/classes"   >
        <sourceroots>
                 <pathelement location="${src}/bank_aspect" />              
        </sourceroots>

         <classpath>
                <pathelement location="${lib}/aspectjrt-1.8.6.jar"/>
        </classpath>
    </iajc>
  </target>

My folder structure show below image and all aspect file content under bank_aspect folder.

enter image description here

This is the error, coming when I run 'Ant' command in Command Promt.

enter image description here

Could you help me to avoid this error?

Which version of apache ant is compatible with OS X 10.7.5?

Im fairly new to ant so please bare with me! Ive had so much trouble in installing ant. I first downloaded it from the apache website, had some errors. Then I finally figured out a way to install through terminals 'brew install ant'; which it worked after downloading Xcode and configuring bash_profile.

So my question is, why does it show that the version is 1.8.2? instead of 1.9.7? Is this a compatibility issue? Thanks for all your help :)

This is my output

java web application failing to build

I'm new with annotations and building applications, so I apologize if it's too easy or I asked the wrong type question. I have a custom annotation like this :

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Handler {
    Class value();
}

Now in a java file, say AB.java, I used this annotation like this

@Handler(Msg.class)
public void handleMsg(Msg msg) {
    ...//some code
}

Now when I tried to build the application, by doing this from the location of my build.xml file

ant rebuild content

it says

BUILD FAILED

for this reason

/home/../somePath/AB.java:800 error: cannot find symbol

@Handler(Msg.class)

symbol: method value()

location: @interface Handler

I'm running java version "1.7.0_101" if it matters. Does it matter if maybe this was written with java version "1.7.0_45". Can someone explain why this's happening even though the class Msg exists in my project files?