Setting ivy home directory in Ant - ant

I would like to set the ivy.default.ivy.user.dir to something other than the default ${user.home}/.ivy2. I can do this on the command line with
ant -Divy.default.ivy.user.dir=${WORKSPACE}/IVYCACHE. But, I would like to have it set without a command line arg. I have tried setting this property in my build.xml, my common.xml and my ivysettings.xml. The strange thing is, that it seems to set the default cache to this path, but the verbose output says that there is no default setting for user.dir, so it uses the ${user.home}/.ivy2 path.
Here is the output when I set the user.dir in my build.xml file.
Strangely, it sets the default cache to the path I used for user.dir
[ivy:buildlist] No ivy:settings found for the default reference 'ivy.instance'. A default instance will be used
[ivy:buildlist] Loading jar:file:/usr/local/ant/lib/ivy-2.2.0.jar!/org/apache/ivy/core/settings/ivy.properties
[ivy:buildlist] searching settings file: trying /home/hudson/.hudson/jobs/Next_CI/workspace/ivysettings.xml
[ivy:buildlist] searching settings file: trying /home/hudson/.hudson/jobs/Next_CI/workspace/ivyconf.xml
[ivy:buildlist] searching settings file: trying ivysettings.xml
[ivy:buildlist] searching settings file: trying ivyconf.xml
[ivy:buildlist] no settings file found, using default...
[ivy:buildlist] :: Ivy 2.2.0 - 20100923230623 :: http://ant.apache.org/ivy/ ::
[ivy:buildlist] jakarta commons httpclient not found: using jdk url handling
[ivy:buildlist] :: loading settings :: url = jar:file:/usr/local/ant/lib/ivy-2.2.0.jar!/org/apache/ivy/core/settings/ivysettings.xml
[ivy:buildlist] including url: jar:file:/usr/local/ant/lib/ivy-2.2.0.jar!/org/apache/ivy/core/settings/ivysettings-public.xml
[ivy:buildlist] no default cache defined: set to /home/hudson/.hudson/jobs/Next_CI/workspace/ivy2/cache
[ivy:buildlist] including url: jar:file:/usr/local/ant/lib/ivy-2.2.0.jar!/org/apache/ivy/core/settings/ivysettings-shared.xml
[ivy:buildlist] including url: jar:file:/usr/local/ant/lib/ivy-2.2.0.jar!/org/apache/ivy/core/settings/ivysettings-local.xml
[ivy:buildlist] including url: jar:file:/usr/local/ant/lib/ivy-2.2.0.jar!/org/apache/ivy/core/settings/ivysettings-main-chain.xml
[ivy:buildlist] including url: jar:file:/usr/local/ant/lib/ivy-2.2.0.jar!/org/apache/ivy/core/settings/ivysettings-default-chain.xml
[ivy:buildlist] settings loaded (71ms)
[ivy:buildlist] default cache: /home/hudson/.hudson/jobs/Next_CI/workspace/ivy2/cache
Then later, it claims that user.dir is not set anywhere.
resolve:
[ivy:resolve] Loading jar:file:/usr/local/ant/lib/ivy-2.2.0.jar!/org/apache/ivy/core/settings/ivy.properties
[ivy:resolve] jakarta commons httpclient not found: using jdk url handling
[ivy:resolve] :: loading settings :: file = /home/hudson/.hudson/jobs/Next_CI/workspace/common/ivysettings.xml
[ivy:resolve] no default ivy user dir defined: set to /home/hudson/.ivy2
Here is my build.xml line:
<property name="ivy.default.ivy.user.dir" value="${basedir}/ivy2" />
I have tried adding this line to common/ivysettings.xml and common/common.xml with no luck.

I added the exact line that you have specified in the sample build.xml provided in the ivy binary download and could see the artifacts downloaded in ivy2 subfolder within the samples folder.
...
<property name="ivy.jar.file" value="${ivy.jar.dir}/ivy.jar" />
<property name="ivy.default.ivy.user.dir" value="${basedir}/ivy2" />
...
I am using ivy 2.2 and ant 1.8.2. Can you check if the same works for you?
[Edit]:
From the docs,
Actually all ant properties are
imported into ivy variables when the
configuration is done (if you call ivy
from ant). This means that if you
define an ant property after the call
to configure, it will not be available
as an ivy variable.

The environment variable ANT_OPTS allows to set jvm parameters. So you may put to your ANT_OPTS the same command line argument you invoke 'ant' shell script with. E.g. under m$ windoozer:
ANT_OPTS=-Divy.default.ivy.user.dir=C:/IVYCACHE

Related

Ant failing to find Ivy jar although jar is in ~/.ant/lib

I have the following build.xml solely to demonstrate the problem:
<project
xmlns:ivy="antlib:org.apache.ivy.ant"
name="test" default="test-ivy">
<target name="test-ivy">
<ivy:settings />
</target>
</project>
When invoking it with Ant (1.7.1) I get:
$ ant
Buildfile: build.xml
test-ivy:
BUILD FAILED
/home/voops/test/build.xml:7: Problem: failed to create task or type antlib:org.apache.ivy.ant:settings
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
-/home/voops/.ant/lib
-a directory added on the command line with the -lib argument
Total time: 0 seconds
However the Ivy jar does live in my ~/.ant/lib directory:
$ whoami
voops
$ls /home/voops/.ant/lib/ivy-2.3.0.jar
-rw-rw-r-- 1 voops voops 1222059 Nov 11 14:55 /home/voops/.ant/lib/ivy-2.3.0.jar
It appears that I have to manually indicate where the Ivy jar is located by adding the following element:
<taskdef uri="antlib:org.apache.ivy.ant" resource="org/apache/ivy/ant/antlib.xml" classpath="${user.home}/.ant/lib/ivy-2.3.0.jar"/>
... in my build.xml file. Once this element is added, the build succeeds.
Why is Ant not able to find Ivy even though the Ivy jar is located in the default ~/.ant/lib location and has to be explicitly told to look for it in the said location?
Update: It seems that the above element is only necessary for Ant 1.7.1. For Ant 1.8.2 or Ant 1.9.4, I don't have to add it.
It's due to the XML namespace declaration in the buildfile:
xmlns:ivy="antlib:org.apache.ivy.ant"
Since the prefix ivy: is being used, the uri attribute is needed in the taskdef task to allow calling the task with the prefix:
An example is shown in the typedef documentation:
uri: The uri that this definition should live in. since Ant 1.6
EDIT:
The antlib indicates that Ant by default can load the correct resource if the antlib is placed in the home directory of Ant:
When Ant encounters a element with a namespace URI with this pattern, it will check to see if there is a resource of the name antlib.xml in the package directory in the default classpath.

How to get the ant build xml file's own name?

let's say I have a file named build_dev_linux.xml.
My question is
How can I find the ant script XML file's own name, build_dev_linux.xml
so I can put it on variable or property in that XML file.?
Ant defines a useful list of built-in properties:
basedir the absolute path of the project's basedir (as set
with the basedir attribute of <project>).
ant.file the absolute path of the buildfile.
ant.version the version of Ant
ant.project.name the name of the project that is currently executing;
it is set in the name attribute of <project>.
ant.project.default-target
the name of the currently executing project's
default target; it is set via the default
attribute of <project>.
ant.project.invoked-targets
a comma separated list of the targets that have
been specified on the command line (the IDE,
an <ant> task ...) when invoking the current
project.
ant.java.version the JVM version Ant detected; currently it can hold
the values "1.2", "1.3",
"1.4", "1.5" and "1.6".
ant.core.lib the absolute path of the ant.jar file.
The ant.file property is what you need. If you want just the file name without the path then you can use the basename task like
<basename file="${ant.file}" property="buildfile"/>

Could not create task or type: getProjectData from Ant

I am trying to run an Ant task from within IBM RSA IDE using Ant build ...
I get the following error message:
BUILD FAILED
build.xml:21: Could
not create task or type of type: getProjectData.
Ant could not find the task or a class this task relies upon.
This is common and has a number of causes; the usual
solutions are to read the manual pages then download and
install needed JAR files, or fix the build file:
- You have misspelt 'getProjectData'.
Fix: check your spelling.
- The task needs an external JAR file to execute
and this is not found at the right place in the classpath.
Fix: check the documentation for dependencies.
Fix: declare the task.
- The task is an Ant optional task and the JAR file and/or libraries
implementing the functionality were not found at the time you
yourself built your installation of Ant from the Ant sources.
Fix: Look in the ANT_HOME/lib for the 'ant-' JAR corresponding to the
task and make sure it contains more than merely a META-INF/MANIFEST.MF.
If all it contains is the manifest, then rebuild Ant with the needed
libraries present in ${ant.home}/lib/optional/ , or alternatively,
download a pre-built release version from apache.org
- The build file was written for a later version of Ant
Fix: upgrade to at least the latest release version of Ant
- The task is not an Ant core or optional task
and needs to be declared using <taskdef>.
- You are attempting to use a task defined using
<presetdef> or <macrodef> but have spelt wrong or not
defined it at the point of use
Remember that for JAR files to be visible to Ant tasks implemented
in ANT_HOME/lib, the files must be in the same directory or on the
classpath
Please neither file bug reports on this problem, nor email the
Ant mailing lists, until all of these causes have been explored,
as this is not an Ant bug.
Here's the Ant buildfile:
<!-- Get property locationName. -->
<target name="config">
<echo message="${ear.project.name}" />
<getProjectData projectName="${ear.project.name}" />
</target>
I am not quite sure what the problem is here because the error message seems not helpful. Any suggestions?
I believe getProjectData is an IBM extension to ant. Like you, I had a similar error, but I was able to get it working after ensuring the Run in the same JRE as the workspace option was enabled (which you can find by right-clicking the build file, run-as, Ant Build..., and selecting the option on the JRE tab).
I discovered the solution on the IBM info center:
The Run in the same JRE as the workspace option enables the classpath
of the workbench to access the additional Ant tasks that perform
operations that are specific to the workbench, such as projectImport,
projectBuild, workspaceBuild, ejbDeploy, or earExport. If your Ant
build script uses any Ant tasks that perform workbench operations,
verify that you selected the Run in the same JRE as the workspace
option; otherwise you might get the following error message in the
Console view:
Problem: failed to create task or type <Ant task> Cause:
The name is undefined.
The build file I used looked like this:
<?xml version="1.0"?>
<project name="Test" default="config" basedir=".">
<target name="config">
<getProjectData Basedir="${basedir}" />
<echo message="getProjectData: projectName=${projectName}
nature=${natureName}
workspace=${workspaceName}
basedir=${basedir}" />
</target>
</project>
And output:
Buildfile: C:\DATA\java\workspace\test-java\build.xml
config:
[getProjectData] Setting projectName=test-java
[getProjectData] Retrieved following Project Data :
[getProjectData] workspaceName=C:\DATA\java\workspace
[getProjectData] natureName=Java
[echo] getProjectData: projectName=test-java
nature=Java
workspace=C:\DATA\java\workspace
basedir=C:\DATA\java\workspace\test-java
BUILD SUCCESSFUL
Total time: 78 milliseconds

Liferay ant deploy failure

I have been having trouble deploying liferay portlets and themes from the command line with ant deploy;
sample execution:
pwd: C:\liferay-plugins-sdk\themes
create.bat deep-blue "Deep Blue"
cd deep-blue-theme
ant deploy
-> Buildfile: C:\liferay-plugins-sdk\themes\deep-blue-theme\build.xml
-> compile:
-> BUILD FAILED
-> C:\liferay-plugins-stk\themes\build-common-theme.xml:172: C:\liferay-plugins-sdk\themes\deep-blue-theme\liferay-portal-6.0.6 omcat-6.0.29webappsROOT\html\themes_unstyled does not exist.
the problem appears to be with the bold section and how the path is obviously incorrect; where is this directory being set?
edit:
the problem was my app.server.dir in build.{username}.properties
The error is a result of the ant build not being able to find a Liferay installation (which contains items needed by the SDK).
By default, the build properties in the SDK are set up on the assumption that your setup looks like this:
- Your Development Directory
- bundles
- data
- deploy
- license
- tomcat-6.0.29
- liferay-plugins-sdk
Where bundles contains a Liferay bundle distribution, including the bundled Tomcat server.
You can see this setup in the build.properties file at the root level of your SDK.
#
# Specify the paths to an unzipped Tomcat bundle.
#
app.server.type=tomcat
app.server.dir=${project.dir}/../bundles/tomcat-6.0.29
app.server.deploy.dir=${app.server.dir}/webapps
app.server.lib.global.dir=${app.server.dir}/lib/ext
app.server.portal.dir=${app.server.dir}/webapps/ROOT
The recommended way to change this is not to edit this section of build.properties, but to create overriding entries in a new file, called build.username.properties. (where username is your user name on your computer account).
As you say in the comment to kirkz's answer, you have already set your build.connor.properties: You obviously have used backslash in there. Here \t is short for the tab character. This explains what you see: ...liferay-portal-6.0.6 omcat... (there's a tab between 6.0.6 and omcat)
Do only use forward-slash in properties files (when you refer to file names, no matter if you're on windows or on any other platforms)
I think to solve this issue just for now. To check weather you are getting unsuccessful build or not you can try this solution:
I have just used the static liferay path in this solution.
<elseif>
<equals arg1="${theme.parent}" arg2="classic" />
<then>
<copy todir="docroot" overwrite="true">
<fileset
dir="C:/Liferay/liferay-portal-6.2-ce-ga2/tomcat-7.0.42/webapps/ROOT/html/themes/classic"
excludes="_diffs/**,templates/**"
/>
</copy>
<copy todir="docroot/templates" overwrite="true">
<fileset
dir="C:/Liferay/liferay-portal-6.2-ce-ga2/tomcat-7.0.42/webapps/ROOT/html/themes/classic/templates"
includes="*.${theme.type}"
/>
</copy>
</then>
</elseif>
After setting up this code in your build-common-theme.xml file you will NOT get omcat-6.0.29webappsROOT\html\themes_unstyled error at least.

ftp task hangs with ant

I'm trying to pull out the file through ftp within ant, it get hung with after printing "getting files", so I enabled debug in ant and my output is
[root#LODIVM11SE001 net]# ant -d -f ftp_t.xml
Apache Ant version 1.6.5 compiled on June 2 2005
Buildfile: ftp_t.xml
Adding reference: ant.PropertyHelper
Detected Java version: 1.5 in: /root/jdk1.6.0_10/jre
Detected OS: Linux
Adding reference: ant.ComponentHelper
Setting ro project property: ant.version -> Apache Ant version 1.6.5 compiled on June 2 2005
Setting ro project property: ant.file -> /Test_Framework/tasks/net/ftp_t.xml
Adding reference: ant.projectHelper
Adding reference: ant.parsing.context
Adding reference: ant.targets
parsing buildfile /Test_Framework/tasks/net/ftp_t.xml with URI = file:///Test_Framework/tasks/net/ftp_t.xml
Setting ro project property: ant.project.name -> FTP simple interface - ftp.xml
Adding reference: FTP simple interface - ftp.xml
Setting ro project property: ant.file.FTP simple interface - ftp.xml -> /Test_Framework/tasks/net/ftp_t.xml
Project base dir set to: /Test_Framework/tasks/net
+Target:
+Target: ftpget
Setting project property: ftpServerName -> xxxxx
Setting project property: ftpUser -> xxxxx
Setting project property: ftpPassword -> xxxx
Setting project property: ftpRemoteDir -> /test
Setting project property: ftpRemoteFile -> ReadMe.txt
Setting project property: ftpLocalDir -> /local/test
Attempting to create object of type org.apache.tools.ant.helper.DefaultExecutor
Adding reference: ant.executor
Build sequence for target(s) `ftpget' is [ftpget]
Complete build sequence is [ftpget, ]
ftpget:
[echo] FTP getting 'ReadMe.txt' from '/test' to '/local/test'
[ftp] Opening FTP connection to xxxxx
[ftp] connected
[ftp] logging in to FTP server
[ftp] login succeeded
[ftp] changing the remote directory
[ftp] getting files
Could not load a dependent class (com/sun/media/jai/codec/FileSeekableStream) for type image
Could not load a dependent class (com/jcraft/jsch/UserInfo) for type sshexec
Could not load a dependent class (com/jcraft/jsch/UserInfo) for type scp
Could not load a dependent class (jdepend/xmlui/JDepend) for type jdepend
Could not load a dependent class (junit/framework/Test) for type junit
fileset: Setup scanner in dir /local/test with patternSet{ includes: [ReadMe.txt] excludes: [] }
My code
<target name="ftpget" description="Get file over FTP">
<fail message="Build Abrted! Failed to find property:ftpRemoteFile" unless="ftpRemoteFile"/>
<fail message="Build Abrted! Failed to find property:ftpLocalDir" unless="ftpLocalDir"/>
<echo message="FTP getting '${ftpRemoteFile}' from '${ftpRemoteDir}' to '${ftpLocalDir}'"/>
<ftp action="get"
server="${ftpServerName}"
userid="${ftpUser}"
password="${ftpPassword}"
verbose="true"
remotedir="${ftpRemoteDir}"
skipFailedTransfers="true">
<fileset dir="${ftpLocalDir}">
<include name="${ftpRemoteFile}"/>
</fileset>
</ftp>
Note: Normal ftp is working fine. I'm using Linux 64bit, ant 1.6.5 and java 1.6.10
Looks like everything works fine until you actually try and retrieve the data. FTP uses two channels; one for control and one for data. This works out fine until a firewall denies the data connection. Passive mode attempts to work around this. Does your FTP library work have a 'passive mode', or 'PASV' option?
Ant FTP task has require dependencies, Libraries that must be on classpath for it to function properly. See link below,
http://ant.apache.org/manual/install.html#commons-net
To use the FTP task, you need jakarta-oro 2.0.8 or later, and commons-net

Resources