Which "empty directories" are being copied by ant? - ant

On a project that uses ant as a build tool, I have the following simplified directory structure:
src/
com/
foo/
bar/
(some files)
bar2/
(some other files)
And the following simplified ant script:
<project default="all">
<target name="all">
<delete dir="dst"/>
<mkdir dir="dst"/>
<copy todir="dst">
<fileset dir="src" excludes="com/foo/bar/*"/>
</copy>
</target>
</project>
When I run this ant script, I see the following output:
all:
[delete] Deleting directory /home/grodriguez/workspace/_test/anttest/dst
[mkdir] Created dir: /home/grodriguez/workspace/_test/anttest/dst
[copy] Copying 1 file to /home/grodriguez/workspace/_test/anttest/dst
[copy] Copied 4 empty directories to 1 empty directory under /home/grodriguez/workspace/_test/anttest/dst
Question: Why is ant reporting that "4 empty directories" are being copied? Shouldn't that be 1 empty directory (com/foo/bar)?

Creating the directory com/foo/bar implies first creating com and then com/foo - i.e. three directories.
My version of Ant is slightly more verbose and shows each creation action:
$ ant -v
Apache Ant(TM) version 1.10.2 compiled on February 3 2018
... deleted for brevity ....
[mkdir] Created dir: /stack/ant/dst
[copy] com/foo/bar2/x.txt added as com/foo/bar2/x.txt doesn't exist.
[copy] omitted as /stack/ant/dst is up to date.
1 [copy] com added as com doesn't exist.
2 [copy] com/foo added as com/foo doesn't exist.
3 [copy] com/foo/bar added as com/foo/bar doesn't exist.
4 [copy] com/foo/bar2 added as com/foo/bar2 doesn't exist.
[copy] Copying 1 file to /stack/ant/dst
[copy] Copying /stack/ant/src/com/foo/bar2/x.txt to /stack/ant/dst/com/foo/bar2/x.txt
[copy] Copied 4 empty directories to 1 empty directory under /stack/ant/dst
When bar2 is created it is (obviously) empty and so gets included in the count of four, even though it is non-empty by the time the copy completes.

Related

Grails 2.5.4 WAR packaging error

I am trying to build a war from a grails 2.5.4 project but I am getting an error.
.Error
|
WAR packaging error: error=2, No such file or directory
Here is the command I ran and the full trace.
grails dev war --plain-output --stacktrace --verbose
Base Directory: /Users/anupshrestha/workspaces/biblio
|Loading Grails 2.5.4
|Configuring classpath
.
|Environment set to development
.................................
|Packaging Grails application
..................................................
|Compiling 4 GSP files for package [biblio]
..
|Compiling 2 GSP files for package [springSecurityCore]
. [mkdir] Created dir: /Users/anupshrestha/workspaces/biblio/target/work/stage
.
|Building WAR file
[copy] Copying 406 files to /Users/anupshrestha/workspaces/biblio/target/work/stage
[copy] Copied 121 empty directories to 2 empty directories under /Users/anupshrestha/workspaces/biblio/target/work/stage
............... [mkdir] Created dir: /Users/anupshrestha/workspaces/biblio/target/work/stage/plugins/resources-1.2.14
. [copy] Copying 7 files to /Users/anupshrestha/workspaces/biblio/target/work/stage/plugins/resources-1.2.14
.......... [copy] Copying 5 files to /Users/anupshrestha/workspaces/biblio/target/work/stage/WEB-INF/grails-app
[copy] Copied 4 empty directories to 1 empty directory under /Users/anupshrestha/workspaces/biblio/target/work/stage/WEB-INF/grails-app
. [copy] Copying 659 files to /Users/anupshrestha/workspaces/biblio/target/work/stage/WEB-INF/classes
. [copy] Copying 1354 files to /Users/anupshrestha/workspaces/biblio/target/work/stage/WEB-INF/classes
. [mkdir] Created dir: /Users/anupshrestha/workspaces/biblio/target/work/stage/WEB-INF/spring
.. [copy] Copying 3 files to /Users/anupshrestha/workspaces/biblio/target/work/stage/WEB-INF/classes
. [copy] Copying 152 files to /Users/anupshrestha/workspaces/biblio/target/work/stage/WEB-INF/lib
. [copy] Copying 1 file to /Users/anupshrestha/workspaces/biblio/target/work/stage/WEB-INF
. [delete] Deleting: /Users/anupshrestha/workspaces/biblio/target/work/resources/web.xml
. [copy] Copying 4 files to /Users/anupshrestha/workspaces/biblio/target/work/stage/WEB-INF/lib
...[propertyfile] Updating property file: /Users/anupshrestha/workspaces/biblio/target/work/stage/WEB-INF/classes/application.properties
[mkdir] Created dir: /Users/anupshrestha/workspaces/biblio/target/work/stage/WEB-INF/plugins/mongodb-5.0.12.RELEASE
. [copy] Copying 1 file to /Users/anupshrestha/workspaces/biblio/target/work/stage/WEB-INF/plugins/mongodb-5.0.12.RELEASE
.. [mkdir] Created dir: /Users/anupshrestha/workspaces/biblio/target/work/stage/WEB-INF/plugins/cache-1.1.8
. [copy] Copying 1 file to /Users/anupshrestha/workspaces/biblio/target/work/stage/WEB-INF/plugins/cache-1.1.8
... [mkdir] Created dir: /Users/anupshrestha/workspaces/biblio/target/work/stage/WEB-INF/plugins/webxml-1.4.1
. [copy] Copying 1 file to /Users/anupshrestha/workspaces/biblio/target/work/stage/WEB-INF/plugins/webxml-1.4.1
... [mkdir] Created dir: /Users/anupshrestha/workspaces/biblio/target/work/stage/WEB-INF/plugins/resources-1.2.14
. [copy] Copying 2 files to /Users/anupshrestha/workspaces/biblio/target/work/stage/WEB-INF/plugins/resources-1.2.14
.. [copy] Copying 2 files to /Users/anupshrestha/workspaces/biblio/target/work/stage/WEB-INF/classes
. [mkdir] Created dir: /Users/anupshrestha/workspaces/biblio/target/work/stage/WEB-INF/plugins/spring-security-cas-2.0-RC1
. [copy] Copying 1 file to /Users/anupshrestha/workspaces/biblio/target/work/stage/WEB-INF/plugins/spring-security-cas-2.0-RC1
... [mkdir] Created dir: /Users/anupshrestha/workspaces/biblio/target/work/stage/WEB-INF/plugins/spring-security-core-2.0-RC4
. [copy] Copying 11 files to /Users/anupshrestha/workspaces/biblio/target/work/stage/WEB-INF/plugins/spring-security-core-2.0-RC4
... [mkdir] Created dir: /Users/anupshrestha/workspaces/biblio/target/work/stage/WEB-INF/plugins/spring-security-ldap-2.0.1
. [copy] Copying 1 file to /Users/anupshrestha/workspaces/biblio/target/work/stage/WEB-INF/plugins/spring-security-ldap-2.0.1
... [mkdir] Created dir: /Users/anupshrestha/workspaces/biblio/target/work/stage/WEB-INF/plugins/ldap-0.8.2
. [copy] Copying 1 file to /Users/anupshrestha/workspaces/biblio/target/work/stage/WEB-INF/plugins/ldap-0.8.2
... [mkdir] Created dir: /Users/anupshrestha/workspaces/biblio/target/work/stage/WEB-INF/plugins/xss-sanitizer-0.4.0
. [copy] Copying 1 file to /Users/anupshrestha/workspaces/biblio/target/work/stage/WEB-INF/plugins/xss-sanitizer-0.4.0
.. [copy] Copying 2 files to /Users/anupshrestha/workspaces/biblio/target/work/stage/WEB-INF/classes
. [mkdir] Created dir: /Users/anupshrestha/workspaces/biblio/target/work/stage/WEB-INF/plugins/quartz-1.0.1
. [copy] Copying 1 file to /Users/anupshrestha/workspaces/biblio/target/work/stage/WEB-INF/plugins/quartz-1.0.1
... [mkdir] Created dir: /Users/anupshrestha/workspaces/biblio/target/work/stage/WEB-INF/plugins/codenarc-0.25.2
. [copy] Copying 1 file to /Users/anupshrestha/workspaces/biblio/target/work/stage/WEB-INF/plugins/codenarc-0.25.2
.... [delete] Deleting directory /Users/anupshrestha/workspaces/biblio/target/work/stage
.Error
|
WAR packaging error: error=2, No such file or directory
There are many possibilities:
First try to restart your IDE
Not solved? Check below steps:
When we run compile or create war command it create files and stores them by default in the project's working directory. Where default directory name is target
If our project workspace contains previously created war. It will not deleted automatically. It will overwritten with new.
SO run the clean command and check the contents of the target directory. If still you notice that target/work directory still exists.
run clean-all command and now check target/work are deleted or not.
Now try to create war
If still getting issue then exclude particular classes or jars which cause to create war
Hope this help's you
I had a similar error with message:
| Error WAR packaging error: /Users/xxx/.grails/2.5.3/projects/my-proyect/resources/grails-app does not exist.
The error was caused by removing i18n directory. Fix is to re-instate the i18n directory and add an empty messages.properties file.
Reference

How to Use xmltask.jar inside build.xml placed inside any_path/ant/lib folder inspite of having pre-installed ant in the enviromnent

I have ant installed in my RedHat 7 machine. I have a project which has ant libraries inside lib folder. That lib folder is present inside installer. There is a jar file known as xmltask.jar inside lib folder. I had defined
<property name="dependencyfinder.home" value="."/>
<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask">
<classpath location="${dependencyfinder.home}/lib/xmltask.jar"/>
</taskdef>
In that line i am getting
BUILD FAILED
installer\build.xml:37: taskdef class com.oopsconsultancy.xmltask.ant.XmlTask cannot be found
using the classloader AntClassLoader[]
Total time: 296 milliseconds
I am using an install script for executing build.xml which is responsible to set the class path.
The code for the script is as follows:
OLD_DIR=$(pwd)
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
cd ${SCRIPT_DIR}
ANT_HOME=$SCRIPT_DIR/ant
ANT_LIB=${ANT_HOME}/lib
${ANT_HOME}/bin/ant -q -e
cd ${OLD_DIR}
exit 0

Ant ignoring copy task file?

I have the following :
<mkdir dir="${build.dir}/serverNIO" />
<copy todir="${build.dir}/serverNIO" overwrite="true" verbose="true">
<fileset dir="resources/serverresources">
<include name="*.properties" />
</fileset>
</copy>
I want to copy the properties file from one folder to the other, all other tasks work fine except this one.
Why does this happen? I do not even get any error message,and the file are in the location mentioned.
So when I try to run my server:
MacBook-Pro:ClientServerNio ramapriyasridharan$ ant run_server
Buildfile: /Users/ramapriyasridharan/Downloads/ClientServerNio/build.xml
init:
[mkdir] Created dir: /Users/ramapriyasridharan/Downloads/ClientServerNio/bin
[mkdir] Created dir: /Users/ramapriyasridharan/Downloads/ClientServerNio/dist
compile_server:
[mkdir] Created dir: /Users/ramapriyasridharan/Downloads/ClientServerNio/bin/serverNIO
[copy] Copying 1 file to /Users/ramapriyasridharan/Downloads/ClientServerNio/bin/serverNIO
[copy] Copying /Users/ramapriyasridharan/Downloads/ClientServerNio/resources/serverresources/server.properties to /Users/ramapriyasridharan/Downloads/ClientServerNio/bin/serverNIO/server.properties
init:
compile_common_server:
[javac] Compiling 3 source files to /Users/ramapriyasridharan/Downloads/ClientServerNio/bin/serverNIO
init:
compile_database_api:
[javac] Compiling 1 source file to /Users/ramapriyasridharan/Downloads/ClientServerNio/bin/serverNIO
[javac] Compiling 5 source files to /Users/ramapriyasridharan/Downloads/ClientServerNio/bin/serverNIO
jar_server:
[jar] Building jar: /Users/ramapriyasridharan/Downloads/ClientServerNio/dist/server.jar
run_server:
[java] Exception in thread "main" java.io.FileNotFoundException: /ClientServerNio/bin/serverNIO/server.properties (No such file or directory)
[java] at java.io.FileInputStream.open(Native Method)
[java] at java.io.FileInputStream.<init>(FileInputStream.java:146)
[java] at java.io.FileInputStream.<init>(FileInputStream.java:101)
[java] at ch.ethz.rama.asl.server.MessageServer.main(Unknown Source)
[java] Java Result: 1
EDIT :
Now it suddenly seems to copy files, only thing is my server program cannot find the properties file,even tought its in the same directory, what should I do?
The Ant script copies server.properties to...
/Users/ramapriyasridharan/Downloads/ClientServerNio/bin/serverNIO/server.properties
...but the Java program launched in the run_server target is looking for the file at...
/ClientServerNio/bin/serverNIO/server.properties
To fix this, either:
<copy> in the Ant script needs to copy server.properties to /ClientServerNio/bin/serverNIO
MessageServer.main needs to change so it looks for server.properties under /Users/ramapriyasridharan

Ant Build failing because of wrong classpath to JBoss server

How can I fix it or where do I fix it?
It should point to:
C:\jboss\jboss-5.1.0.GA\server\default\lib
Console log
C:\PSC Updated\src>ant build-ejb
Buildfile: C:\PSC Updated\src\build.xml
clean:
build-core:
[mkdir] Created dir: C:\PSC Updated\src\build\classes
[javac] Compiling 159 source files to C:\PSC Updated\src\build\classes
BUILD FAILED
C:\PSC Updated\src\build.xml:110: C:\home\apps\jboss-5.1.0.GA\server\default\lib does not exist.
Worked: When I pointed to my {jboss.home}\server\default\lib
Try double slash for windows path on ant files.
C:\\jboss\\jboss-5.1.0.GA\\server\\default\\lib
Could you post your build.xml for more clarification.

ANT error: failed to create task or type antlib:com.salesforce:deploy

I've started to play with the Force.com Migration Tool. I want to use it from an ANT build file. I've created this one:
<project name="Subversion to Org" default="deploy" basedir="." xmlns:sf="antlib:com.salesforce">
<target name="deploy">
<echo message="deploying from metadata" />
<echo message="ANT_HOME=${ant.home}"/>
<echo message="BASEDIR=${basedir}"/>
<echo message="ANT_CORE_LIB=${ant.core.lib}"/>
<echo message="JAVA_VERSION=${ant.java.version}"/>
<echo message="ANT_LIBRARY_DIR=${ant.library.dir}"/>
<echo message="classpath=${java.class.path}"/>
<sf:deploy username="${properties.username}"
password="${properties.password}"
serverurl="${properties.url}"
deployroot="${properties.root}"
singlePackage="${properties.singlePackage}"
runAllTests="${properties.allTest}" />
</target>
</project>
I've copied the ant-salesforce.jar in ant.lib folder. When I execute this file throught ANT I get this:
Buildfile: build.xml
deploy:
[echo] deploying from metadata
[echo] ANT_HOME=/usr/share/ant
[echo] BASEDIR=/usr/share/tomcat6/.jenkins/jobs/Salesforce Deploy Test/workspace/deploy script
[echo] ANT_CORE_LIB=/usr/share/java/ant-1.7.1.jar
[echo] JAVA_VERSION=1.6
[echo] ANT_LIBRARY_DIR=/usr/share/ant/lib
[echo] classpath=/usr/share/java/ant.jar:/usr/share/java/ant-launcher.jar:/usr/share/java/jaxp_parser_impl.jar:/usr/share/java/xml-commons-apis.jar:/usr/lib/jvm/java/lib/tools.jar:/usr/share/ant/lib/ant.jar:/usr/share/ant/lib/ant-launcher.jar:/usr/share/ant/lib/ant-salesforce.jar:/usr/share/ant/lib/ant-bootstrap.jar
BUILD FAILED
/usr/share/tomcat6/.jenkins/jobs/Salesforce Deploy Test/workspace/deploy script/build.xml:16: Problem: failed to create task or type antlib:com.salesforce:deploy
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
No types or tasks have been defined in this namespace yet
This appears to be an antlib declaration.
Action: Check that the implementing library exists in one of:
-/usr/share/ant/lib
-/root/.ant/lib
-a directory added on the command line with the -lib argument
Total time: 0 seconds
It seems that ant-salesforce.jar file it isn't found, but it appears listed in the output. Any ideas?
More info:
Permissions check
ls -al /usr/share/ant/lib
total 3412
drwxr-xr-x. 2 root root 4096 feb 12 15:36 .
drwxr-xr-x. 4 root root 4096 feb 12 09:49 ..
lrwxrwxrwx. 1 root root 28 feb 12 09:49 ant-bootstrap.jar -> ../../java/ant-bootstrap.jar
lrwxrwxrwx. 1 root root 18 feb 12 09:49 ant.jar -> ../../java/ant.jar
lrwxrwxrwx. 1 root root 27 feb 12 09:49 ant-launcher.jar -> ../../java/ant-launcher.jar
-rwxrwxrwx. 1 root root 3483648 feb 12 12:58 ant-salesforce.jar
Jar contents check:
...
com/salesforce/ant/BulkRetrieveTask.class
com/salesforce/ant/CompileAndTest$CodeNameElement.class
com/salesforce/ant/CompileAndTest$RunTestsElement.class
com/salesforce/ant/CompileAndTest.class
com/salesforce/ant/Configuration.class
com/salesforce/ant/ConnectionFactory.class
com/salesforce/ant/DeployTask$CodeNameElement.class
com/salesforce/ant/DeployTask.class
com/salesforce/ant/DescribeMetadataTask.class
com/salesforce/ant/ListMetadataTask.class
com/salesforce/ant/RetrieveTask$PackageManifestParser.class
com/salesforce/ant/RetrieveTask.class
com/salesforce/ant/SFDCAntTask.class
com/salesforce/ant/SFDCMDAPIAntTask.class
com/salesforce/ant/SFDCMDAPIAntTaskRunner.class
com/salesforce/ant/ZipUtil.class
com/salesforce/antlib.xml
...
antlib File contents (as expected):
<antlib>
<typedef name="compileAndTest" classname="com.salesforce.ant.CompileAndTest"/>
<typedef name="deploy" classname="com.salesforce.ant.DeployTask"/>
<typedef name="retrieve" classname="com.salesforce.ant.RetrieveTask"/>
<typedef name="bulkRetrieve" classname="com.salesforce.ant.BulkRetrieveTask"/>
<typedef name="listMetadata" classname="com.salesforce.ant.ListMetadataTask"/>
<typedef name="describeMetadata" classname="com.salesforce.ant.DescribeMetadataTask"/>
</antlib>
Thanks in advance.
Your syntax for sf:deploy is good. Matches mine.
Check your project definition. Are you setting the namespace of xmlns:sf to the right value?
Should be:
<project name="salesforce" default="deploy" basedir="." xmlns:sf="antlib:com.salesforce">
You could also check the permissions of ant-salesforce.jar.
And then check that the jar is not corrupted
jar -tf ant-salesforce.jar
Resolved: I've reinstalled ant and now all seems to work OK. Weird thing.
Thanks for your support guys
I got the same issue, fixed it by changing the permission to the ant-salesforce.jar lib.
for the ones getting this issue it's worth checking if it isn't a permission issue on the lib.

Resources