I'm pretty sure this has been asked before but I can't seem to find the correct answer after spending quite some time googling... :)
Anyway, in our build server, we have two (2) different versions of Grails and Java running; one is 1.3.3 with JDK 1.5 while the other is 1.3.6 with JDK 1.6. Now, when building/creating the WAR file for these 2 projects, we pretty much need to switch the environment variables for GRAILS_HOME and JAVA_HOME automatically via the ANT script... for which I am a total noob >.<
Consider:
...
<target name="clean">
...
</target>
<target name="war" depends="clean">
...
</target>
...
If I set the env't variables at the time clean is being done, it will, of course, not be the same when war is run (I've tried using batch files and even if it worked, it was messy and not DRY... hence, I'm looking for alternatives).
Now, I've seen macrodef being tossed around a few forums but I can't seem to get a clear sample on how to do it for this case. Any suggestions on what I can do or some pointers?
Any help would be appreciated.
Thanks much!
I have a similar use case and I'm also googling for the same. Till now I've got these, I will try these reaching office tomorrow.
<java classname="ShowJavaVersion" classpath="."
jvm="path-to-java14-home/bin/java" fork="true"
taskname="java1.4">
<property environment="env"/>
<exec ...>
<env key="PATH" path="${env.PATH}:${basedir}/bin"/>
</exec>
Executing batch file.
Related
I'm using ant scripts for initializing my exist-db.
But, I have this script below (dummy version) which is working in my local platform and not on my procution one. As I'm not the one who handle the configuration of this database, I don't know where to look in the conf to fix this.
Here is the script (which is just trying to add a new user) :
<project basedir="." default="default" name="ANTProject">
<property file="load.properties"/>
<path id="classpath.core">
<fileset dir="${path}/lib/core">
<include name="*.jar"/>
</fileset>
<pathelement path="${path}\exist.jar"/>
<pathelement path="${path}\exist-optional.jar"/>
</path>
<typedef resource="org/exist/ant/antlib.xml" uri="http://exist-db.org/ant">
<classpath refid="classpath.core"/>
</typedef>
<target name="default">
<echo message="Création du compte ${login}"/>
<xdb:adduser xmlns:xdb="http://exist-db.org/ant"
uri="xmldb:exist://${exist.uri}/exist/xmlrpc/db"
name="${login}" secret="${password}" primaryGroup="${user.group}" user="${root.login}"
password="${root.password}"/>
</target>
</project>
I get this error message :
XMLDB exception caught: No such handler: Default.setUser
I get the same thing if I use xdb:users task, but the xdb:store is working well... I'm running exist 2.1, in both my local and production plateform, and as already told, same scripts working well on local one...
I guess, it's something about the exist configuration, but I didn't find anything on enabling this tasks in the documentation.
If someone could help...
Ok, I got it.
Just for completeness, It was an issue on jar librairies. It seems I used ones which support xdb:store, but not others tasks (didn't find any release version of this)...
This ant depandancies is quite tricky and It's hard to know what your jars offer...
We are facing langOutOfMemory error, when we run an ant script, basically this script runs a lot tests. One solution is to increase heap size using ANT_OPTS variable in environment. But the problem here is I want to increase heap size via ant script itself.
I have tried couple of ways, but neither helped:
<target name="test1">
<exec executable="ant" dir="${TEST}">
<env key="ANT_OPTS" value="-Xmx2048m"/>
</exec>
</target>
<target name="test1" dir="{TEST}">
<exec executable="sh">
<arg line="ant"/>
<env key="ANT_OPTS" value="-Xmx2048m"/>
</exec>
</target>
Please help on this.
Thanks,
Ashok
It looks like you are trying to run ant within ant using the exec. This is pretty convoluted. As document exec is meant to run system commands.
We are facing langOutOfMemory error, when we run an ant script,
basically this script runs a lot tests
Assuming you are running unit tests written in junit using ant junit task, you can use the maxmemory parameter to specify the memory to be used. You should also be setting fork to true.
If this is not the case, please edit the question with the relevant portion of the ant script.
I wanted to have a look which system properties are set here (and to which values), so the easiest way (if not writing a new Java program here) would be adding some lines to my ant build script:
<target name="properties">
<echoproperties/>
</target>
But running ant gives my this error message:
/u/ebermann/projektoj/stackoverflow-examples/build.xml:19: Problem: failed to create task or type echoproperties
Cause: the class org.apache.tools.ant.taskdefs.optional.EchoProperties was not found.
This looks like one of Ant's optional components.
Action: Check that the appropriate optional JAR exists in
-/usr/share/ant/lib
-/u/ebermann/.ant/lib
-a directory added on the command line with the -lib argument
Do not panic, this is a common problem.
The commonest cause is a missing JAR.
This is not a bug; it is a configuration problem
Okay, so I don't panic, but wonder what to do.
I have Ant 1.7.1 here (an OpenSUSE system), and sadly no documentation for this version, and I'm not root to install either a current ant version or the documentation for the old version (I just downloaded it and it still does not say which jar file is needed here). Of the directories listed above, only /usr/share/ant/lib exists, but it contains nothing like optional.
I would want to download the necessary jar file and put it in my home directory, but where to find it? The ant download archive contains nothing like that, and I have no idea where else to search. (I did google a bit, but did not find anything.
So, can someone give me some pointers where to find the right jar file?
(I suppose the solution is quite easy, and something is just blocking my view.)
After vahapt's answer, I downloaded the file from the apache repository, and put it into the directory /u/ebermann/.ant/lib mentioned by the error message. Running ant properties again - the same result as above.
$ jar -tf /u/ebermann/.ant/lib/ant-nodeps-1.7.1.jar | grep 'EchoProperties.class'
org/apache/tools/ant/taskdefs/optional/EchoProperties.class
This looks like it should work - is the error message simply wrong?
If I put it directly into the CLASSPATH, it works:
$ CLASSPATH=/u/ebermann/.ant/lib/ant-nodeps-1.7.1.jar ant properties
Buildfile: build.xml
properties:
[echoproperties] #Ant properties
[echoproperties] #Thu Mar 10 00:46:22 CET 2011
...
[echoproperties] user.name=ebermann
[echoproperties] user.timezone=
BUILD SUCCESSFUL
Total time: 0 seconds
I don't want to change my normal CLASSPATH variable, and it should work by putting it into this directory, or did I understand something wrong?
Any ideas, or is this an ant bug?
(Also, why is this file nowhere mentioned in the ant documentation?)
Edit:
After the answer from vahapt, my ant build-file looks like this:
<project name="stackoverflow-examples" basedir=".">
<target name="echoproperties.prepare">
<available property="echoproperties.works"
classname="org.apache.tools.ant.taskdefs.optional.EchoProperties"
/>
</target>
<target name="echoproperties.init"
depends="echoproperties.prepare"
unless="echoproperties.works">
<taskdef name="echoproperties" classname="org.apache.tools.ant.taskdefs.optional.EchoProperties">
<classpath>
<fileset dir="${user.home}/.ant/lib">
<include name="ant-nodeps.jar" />
</fileset>
</classpath>
</taskdef>
</target>
<target name="properties" depends="echoproperties.init">
<echoproperties/>
</target>
</project>
This re-registers the task only if it is not already in the ant classpath. (Thus it should also work for complete ant installations which do not have this file in the home directory).
I would still say that This is not a bug; it is a configuration problem is not totally right, even more as putting the file in the indicated directory does not help.
One more interesting observation: The nodeps.jar in ${user.home}/.ant/lib (i.e. now /u/ebermann/.ant/lib/ant-nodeps.jar) is already in the class path (the one shown by ${java.class.path}, but this seems not to help for <echoproperties> to work without this taskdef.
So, this works too:
<target name="echoproperties.init"
depends="echoproperties.prepare"
unless="echoproperties.works">
<taskdef name="echoproperties"
classname="org.apache.tools.ant.taskdefs.optional.EchoProperties"
classpath="${java.class.path}" />
</target>
When you make a google search, results point to ant-nodeps-1.7.1.jar
Make sure that jar exists and you've added it into the classpath
For the second part of your question:
SOLUTION 1. You do not need to modify your CLASSPATH variable. Instead you might add it by adding the parameter -cp [JAR FILE LOCATION] (-cp is for "java" executable)
SOLUTION 2. Jar files are simply zip files, open ant-nodeps.jar copy its content to ant.jar throw away ant-nodeps.jar
SOLUTION 3. See the sample below. taskdef is a ant feature that loads a jar or a class into ClassLoader hierarchy. (You load the class before using it, works like a charm)
<?xml version="1.0" encoding="ASCII"?>
<project name="Test" default="properties" basedir=".">
<target name="properties" depends="init">
<echoproperties/>
</target>
<target name="init">
<taskdef name="echoproperties" classname="org.apache.tools.ant.taskdefs.optional.EchoProperties">
<classpath>
<fileset dir="${ant.library.dir}">
<include name="ant-nodeps.jar" />
</fileset>
</classpath>
</taskdef>
</target>
</project>
I downloaded Ant 1.7.1 and looked in the documentation that came with it. There it described echoproperties as an optional task, but didn't mention where to get the jarfile for this optional task.
Looking inside the lib folder, I discovered the ant-nodeps.jar. Apparently, it was included with Ant 1.7.1.
I would recommend that you download and install Ant 1.8. Since Ant is a Java jar file, it's not really all that difficult to install the latest and greatest version.
I looked on my Mac, and /usr/bin/ant is a link to /usr/share/ant/bin and /usr/share/ant/ is a link to /usr/share/java/ant-1.8.2. So, all I have to do is point /usr/share/ant/bin/ to the correct version of Ant.
In Ant 1.8.2, echoproperties is now a standard task.
I'm having a problem using deploy:deploy-file with snapshots I'd like some advice on please.
I have 2 projects; 1) Ant based and 2) the other Maven based that consumes the jars of the other project via Archiva.
I've added a target to the Ant project to deploy snapshots on every successful build during our iteration.
The problem is the Maven project cannot find them because the name of the dependency has a timestamp appended like so:
someJar-1.0-20100407.171211-1.jar
Here is the Ant target:
<exec executable="${maven.bin}" dir="../lib">
<arg value="deploy:deploy-file" />
<arg value="-DgroupId=com.my.package" /><arg value="-DartifactId=${ant.project.name}" />
<arg value="-Dversion=${manifest.implementation.version}-SNAPSHOT" />
<arg value="-Dpackaging=jar" />
<arg value="-Dfile=../lib/${ant.project.name}-${manifest.implementation.version}-SNAPSHOT.jar" />
<arg value="-Durl=http://archiva.xxx.com/archiva/repository/snapshots" />
<arg value="-DrepositoryId=snapshots" />
</exec>
I have a similar Ant target for releases and this works fine.
Other pure Maven projects which deploy snapshosts via mvn deploy work fine.
Does anyone know where I am going wrong?
Thank You
Update
Figured out the answer, see below.
Figured out the answer.
In my Ant target I was deploying the file as you can see. I also then did the same thing but with the -tests jar.
This resulted in 2 snapshots in Archiva, not the usual 1 has you'd expect if you did mvn deploy.
Therefore the non test dependency could not be found because the latest snapshot was the -test jar.
Would be great to know how to solve this problem.
see Deploying non Maven based module src and tests jar to Archiva in a single transaction
I'm trying to call an Antlr task in my Ant build.xml as follows:
<path id="classpath.build">
<fileset dir="${dir.lib.build}" includes="**/*.jar" />
</path>
...
<target name="generate-lexer" depends="init">
<antlr target="${file.antlr.lexer}">
<classpath refid="classpath.build"/>
</antlr>
</target>
But Ant can't find the task definition. I've put all of the following in that dir.lib.build:
antlr-3.1.jar
antlr-2.7.7.jar
antlr-runtime-3.1.jar
stringtemplate-3.2.jar
But none of those seems to have the task definition. (I've also tried putting those jars in my Ant classpath; same problem.)
The current Antlr-task jar is available at http://www.antlr.org/share/1169924912745/antlr3-task.zip
It can be found on the antlr.org website under the "File Sharing" heading.
You should use the antlrall.jar jar. You can go ahead and just drop it into your Ant installation but that does mean that it will only work for that one install. We check the jar in and use taskdef to load the jar file so that it doesn't become another step for developers when they start on the team or move to a new computer.
Antlr http://ant.apache.org/manual/Tasks/antlr.html
Using taskdef http://www.onjava.com/pub/a/onjava/2004/06/02/anttask.html
I just got this working for myself. Took me an hour. ugh. anyway,
Step 1: download ant-antlr3 task from
http://www.antlr.org/share/1169924912745/antlr3-task.zip
Step 2: copy to where ant can see it. My mac:
sudo cp /usr/local/lib/ant-antlr3.jar /usr/share/ant/lib/
my linux box:
sudo cp /tmp/ant-antlr3.jar /usr/local/apache-ant-1.8.1/lib/
Step 3: make sure antlr2, antlr3, ST are in classpath. All in one is here:
http://antlr.org/download/antlr-3.3-complete.jar
Step 4: use in build.xml
<path id="classpath">
<pathelement location="${antlr3.jar}"/>
<pathelement location="${ant-antlr3.jar}"/>
</path>
<target name="antlr" depends="init">
<antlr:ant-antlr3 xmlns:antlr="antlib:org/apache/tools/ant/antlr"
target="src/T.g"
outputdirectory="build">
<classpath refid="classpath"/>
</antlr:ant-antlr3>
</target>
Just added a faq entry:
http://www.antlr.org/wiki/pages/viewpage.action?pageId=24805671
The most basic way to run Antlr is to execute the Antlr JAR:
<project default="antlr">
<target name="antlr">
<java jar="antlr-4.1-complete.jar" fork="true">
<arg value="grammar.g4"/>
</java>
</target>
</project>
This is a bit slower, because it forks the JVM and it runs Antlr even if the grammar did not change. But it works in the same way with every Antlr version and does not need any special targets.
On Ubuntu this should make it available:
sudo apt-get install ant-optional
Additional info on top of what everybody else contributed so far:
The ant-optional package in Ubuntu includes the task shipped with Ant 1.8.2 which is a task for ANTLR 2.7.2 so this will fail with an error as described in this post. The method described by Terence is the best way to use the ANTLR3 task.
If you do not have root access on a Linux machine, you can install the ant-antlr3.jar file in the Ant user directory: ~/.ant/lib. Check with ant -diagnostics whether ant-antlr3.jar is visible to Ant, as explained in this other post.
If you are using Eclipse, you will need to restart the IDE before it recognises the new task and you will also need to include antlr3.jar and stringtemplate.jar in your classpath (but ant-antlr3.jar is not necessary).