What does out.absolute.dir meaning in linux? - java

nI see in build files of different project in Linux frequently use of "out.absolute.dir" and I'm really curious about what does it exactly mean.So I write a short build file which I mentioned in following lines
<project name="Test_Ant_APK" default="print">
<property name="cal.out.dir" location="${out.absolute.dir}"/>
<target name="print">
<echo>p=${cal.out.dir}</echo>
</target>
</project>
And when I run this build file from command line I got this output
Buildfile: /home/jody/workspace/Test_Ant_APK/build.xml
print:
[echo] p=/home/jody/workspace/Test_Ant_APK/${out.absolute.dir}
BUILD SUCCESSFUL
Total time: 0 seconds
I little confused about output.I think we should have p=/home/jody/workspace/Test_Ant_APK as output. Why we have ${out.absolute.dir}
at the end of output? what does it mean? Does this build file have problem?

Nothing wrong with your buildscript.
You adress a propertyvalue with syntax ${...}, but as the
property out.absolute.dir is not set within the project scope of your ant file it's getting echoed as is => ${out.absolute.dir} which is normal for properties not set - in your case its added to the dir your ant script resides, because of the use of location attribute in property task.
See the difference when using property task with value attribute instead :
<project name="foo">
<property name="cal.out.dir" value="${out.absolute.dir}"/>
<target name="print">
<echo>${cal.out.dir}</echo>
</target>
</project>
output :
[echo] ${out.absolute.dir}
I believe the propertyname $[out.absolute.dir} might be taken in several scripts due to the fact that property task with attribute location means (taken from ant manual) :
Sets the property to the absolute filename of the given file. If the
value of this attribute is an absolute path, it is left unchanged
(with / and \ characters converted to the current platforms
conventions). Otherwise it is taken as a path relative to the
project's basedir and expanded.
see ant manual property task for details.
If you want the value of project name attribute to be echoed, you must use the builtin property ${ant.project.name}, f.e :
<project name="foo">
<echo>$${ant.project.name} => ${ant.project.name}</echo>
</project>
see all builtin properties with :
<project>
<echo>ant builtin properties:</echo>
<echoproperties prefix="ant"/>
<echo>java builtin properties:</echo>
<echoproperties prefix="java"/>
</project>

Related

How to run same Maven profile with different parameters

Work currently uses ANT and need to migrate to MAVEN. As stated above , I need to run same profile but with different parameters each time.
Present Ant Code Example :
<target name = SomeTarget>
<var name = "PROP" value="123">
<antcall target = "OutTarget1">
<var name = "PROP" value="145">
<antcall target = "OutTarget1">
</target>
<target name ="OutTarget1">
<!-- some java code -->
<!-- run .SQL files -->
<!-- some java code on that again -->
<\target>
Doesn't seem like even with maven antrun plugin antcall is supported.
Work requires I create all targets as profiles in pom.xml. Now I can simply repeat the "OutTarget1" code in execution part of a profile for each time there is a new property. But that makes it quite hard to debug. And there's a ton of a t targets calling other targets.
If it was just one antcall , I add the parameter in launch configuration. I have no idea how to achieve this when it's same parameter but different values each time.
P.S. Added what OutTarget does. It's basically the same process but with diff values each time.
I don't think what you're trying to do is a good approach, but if it's urgent...have you considered using different settings-[X].xml, with the same profile defined differently and launch maven pointing to them?

ant propertyfile task update property removes all comments from the property file

I am running ant version 1.6.5 on CentOS 5.5. I used ant propertyfile task (an optional ant task) to update some properties in a property file before loading the property file. The property file task seems to be removing all the existing comments from the file just leaving it with the property key-value pairs.
Here is my code snippet from the build.xml file:
<target name="version">
<propertyfile file="${root.dir}/build/cbo_version.properties" >
<entry key="major_number" value="${major_number}"/>
<entry key="minor_number" value="${minor_number}"/>
<entry key="maintenance_number" value="${maintenance_number}"/>
<entry key="build_number" value="${build_number}"/>
</propertyfile>
</target>
Here is a snippet from my property file:
#
# This file was designed to contain basic information about a build/release such
# as its version, code label, etc. for the purpose of traceability.
#
major_number=1
minor_number=0
maintenance_number=0
build_number=18
Once I build my application, all the lines in the property file prefixed with "#" are deleted. I have tried the same code on mac os x 10.8.4 and with ant 1.8.2 and the code runs perfectly fine. I would like to have the comments left completely untouched by the propertyfile task. Please help
[Edited] Ant docu says about PropertyFile task:
Since Ant 1.8.0 comments and layout of the original properties file are preserved.
http://ant.apache.org/manual/Tasks/propertyfile.html

Ant target failing: Antlib or Ivy issue? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Ivy fails to resolve a dependancy, unable to find cause
I'm trying to run the following build task (initIvy):
<?xml version="1.0" encoding="UTF-8"?>
<project name="myproject-build" default="package" basedir=".." xmlns:ivy="antlib:org.apache.ivy.ant">
<property file="build/build.properties"/>
<property environment="env"/>
<!-- Ant library path, including all of its plugins. -->
<path id="ant.lib.path">
<fileset dir="${env.ANT_HOME}/lib" includes="*.jar"/>
</path>
<!-- CONFIGURE IVY -->
<taskdef resource="org/apache/ivy/ant/antlib.xml"
uri="antlib:org.apache.ivy.ant" classpathref="ant.lib.path"/>
<!-- Use Ivy tasks to resolve dependencies into the local Ivy cache. -->
<target name="initIvy">
<!-- Initialize Ivy and connect to host repository. -->
<echo message="Initializing Apache Ivy and connecting to the host repository."/>
<ivy:settings url="${ivy.std.repo.settings.url}" realm="${ivy.std.repo.realm}" username="${ivy.std.repo.username}" passwd="${ivy.std.repo.password}"/>
<!-- Clear/flush the Ivy cache. -->
<echo message="Cleaning the local Ivy cache for the current build."/>
<ivy:cleancache/>
</target>
<!-- Rest of buildfile omitted for brevity. -->
</project>
When I run ant -buildfile build.xml initIvy I get the following output:
Buildfile: /<path-to-my-project>/build/build.xml
[taskdef] Could not load definitions from resource org/apache/ivy/ant/antlib.xml. It could not be found.
initIvy:
[echo] Initializing Apache Ivy and connecting to the host repository.
BUILD FAILED
/<path-to-my-project>/build/build.xml:81: 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:
-/<path-to-my-ANT_HOME>/lib
-/home/myUser/.ant/lib
-a directory added on the command line with the -lib argument
When I go to ${ANT_HOME}/lib, I don't see any JARs labeled "antlib*.jar".
So I'm guessing I downloaded a version of Ant that did not include Antlib, and now that I'm using Ivy (which uses Antlib), the build is choking?
If this is an Antlib issue, then I believe I want one of the distros available here. If so, can someone confirm which one I should use (that only contains Antlib and not anything else), and confirm the process for installing it; i.e., is it just as simple as putting the correct JAR in ${ANT_HOME}/lib? Etc.
If this is an Ivy issue, then can someone point me in the right direction as to what could be going on?
And if this is neither Antlib nor Ivy, ditto for the question directly above. Thanks in advance!
I think you might be missing Apache IVY library. Download it from here - apache ivy Copy the jar in your ant lib directory.
For example (change version numbers as appropriate):
Download and install Ant (e.g., C:\Apps\Tools\apache-ant-1.9.7).
Download and extract Ivy (e.g., C:\Users\UserName\Downloads\apache-ivy-2.4.0)
Copy C:\Users\UserName\Downloads\apache-ivy-2.4.0\ivy-2.4.0.jar into C:\Apps\Tools\apache-ant-1.9.7\lib.
Ant is configured to use Ivy.

Ant won't import properties

My build begins by defining 2 properties files, importing another build XML, and then commencing with all my other targets & tasks:
build.main.xml:
<project name="${proj.name}" default="assemble" basedir=".">
<!-- BASIC CONFIGURATIONS -->
<!-- Define build properties. -->
<property file="build.main.properties"/>
<property file="build.app.properties"/>
<!-- Imports. -->
<import file="${alt.build.file}"/>
<!-- Rest of buildscript omitted for brevity... -->
</project>
build.app.properties:
proj.name=test-proj
alt.build.file=build.app.xml
It seems that build.main.xml cannot seem to see/find any properties defined inside build.app.properties; specifically:
It cannot resolve ${proj.name}, and when I add the build.main.xml file to the Eclipse Ant view, the name of the build shows up as ${proj.name}
It cannot find build.app.xml imported from build.main.xml
What's going on here? Do ant builds only get to import one properties file or something?!? Where could I start troubleshooting?
Edit: using Eclipse editor my buildscript does not have any red/highlighted syntax errors that might be causing the ant plugin to work incorrectly, etc.
Edit: I am noticing issues with properties defined inside the build.main.properties to. If I try to echo them they don't get noticed by Ant either...
The Ant project name cannot be itself a property for the reason Jochen mentioned in his comment.
Try running your script with the -v option to see more logging. I have used a technique very similar to your <import file="${alt.build.file}"/> to branch my script based on the db platform, so there should be no problem with it.
I wondered if your property files are in the same directory then your build script is.

Java Ant - how to pass a ProGuard task arguments and use them inside a configuration file?

I have this in my build.xml:
<target depends="build-jar" name="proguard">
<taskdef resource="proguard/ant/task.properties" classpath="tools/proguard4.6/lib/proguard.jar" />
<proguard configuration="ant/proguard.conf" />
</target>
It works fine.
Inside the configuration file (i.e "ant/proguard.conf") I'm trying to access properties defined in this build.xml file but I'm always getting this kind of error:
Value of system property 'jar.final_name' is undefined in '<jar.final_name>' in line 1 of file '.......\ant\proguard.conf'
The error is clear. Question is how I do what I'm trying to?
If I'd do it the "Embedded ProGuard configuration options" way I could use these properties like any other property in build.xml, but I'm trying to keep the files separate.
How do I do that then?
By default, Ant doesn't provide a way to set java system properties for its tasks. You can only specify -D options in the ANT_OPTS system variable when starting Ant itself.
I'll consider supporting the use of Ant properties in referenced ProGuard configurations (being the developer of ProGuard).
For the time being, an acceptable solution might be to specify input and output jars in Ant's XML-style:
<proguard configuration="ant/proguard.conf">
<injar name="${injar}" />
<outjar name="${outjar}" />
<libraryjar name="${java.home}/lib/rt.jar" />
</proguard>
This part of the configuration is more closely tied to the Ant script anyway.

Categories