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.
Related
I'm using Ant 1.8.2 with Java 6. I have written a custom task for Ant. How do I set JVM memory settings when this custom task is run? The task resembles …
<target name="Selenium4" depends="checkout-selenium-tests">
<taskdef name="SeleniumHTMLClient" classname="com.cm.systems.selenium.ant.SeleniumRunner">
<classpath refid="selenium-classpath-ref" />
</taskdef>
<SeleniumHTMLClient … arguments …>
...
</SeleniumHTMLClient>
</target>
How would I adjust the memory settings when executing the custom task? Thanks, - Dave
You can't set the memory configuration for your particular task, unless you fork a new JVM to run that task. To set the memory configuration for the Ant job as a whole, use the ANT_OPTS environment variable. See the "running" section of the Ant documentation.
Does using the 'ant' tag in an ant script start a seperate JVM?
My code is like:
<target name="run" description="base tests">
<ant dir="suite1"/>
<ant dir="suite2"/>
<ant dir="suite3"/>
</target
From ANT manual, it says that if we use 'ant' inside target tag, it is not part of same build file, but when I monitor the Java process, only one Java process runs on my machine.
It runs as a separate project within the same JVM
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.
I'm developing an ant script which is calling another ant script using the <ant> task. This ant script is an installer a Java product and is to be used by our customers, who will have ant installed separately.
The script being called uses the antlr task <antlr:ant-antlr3>. To do this I must place the ant-antlr3.jar file in the ant lib directory, as well as adding antlr-3.2.jar to the classpath.
But I don't want to have this dependency of having ant-antl3.jar file in the client's own installed version of ant.
Is there a way of providing the equivalent to ant's command-line '-lib' option to specify other paths for jars to be added to antlib using the <ant> task itself?
I've taken a look at the online docs and there doesn't seem to be a way.
Thanks
I believe the accepted way to do this is to manually set up your classpath in the build file rather than implicitly including it via the global ant lib directory. i.e.
<path id="master-classpath">
<fileset dir="${lib}" />
<fileset file="${findbugs-base}/lib/annotations.jar" />
<pathelement location="${build-classes}" />
</path>
You can then use this path element in any task that can accept classpath args such as javac
<javac
destdir="${out}"
source="1.5"
target="1.5"
debug="true">
<src path="${src}" />
<classpath refid="master-classpath" />
</javac>
This way, the global ant set up isn't a dependency, and you can specify any files you might need for any build, as specifically as you need to (down to a given call or target).
Obviously, this is all to be carried out in the build file you're calling from the clients' build file. This way, when you call out to yours, the classpath will be set up exactly as you desire.
Another far less idiomatic possibility would be to literally shell out with the Exec Task and call ant that way. Obviously, with the provision of the Ant task, the developers of ant don't recommend you doing that. It is an option, nonetheless.
Tim's answer gives most of the story, but in order to run Ant and set JVM options, you'd need to invoke it via the java task.
There is an example of running this way in the Ant docs, here slightly modified to include -lib:
<java
classname="org.apache.tools.ant.launch.Launcher"
fork="true"
failonerror="true"
dir="${sub.builddir}"
timeout="4000000"
taskname="startAnt"
>
<classpath>
<pathelement location="${ant.home}/lib/ant-launcher.jar"/>
</classpath>
<arg value="-lib"/>
<arg value="${path.to.your.antlr.jar}"/>
<arg value="-buildfile"/>
<arg file="${sub.buildfile}"/>
<arg value="${sub.target}"/>
</java>
I am using cruisecontrol and ant to build some legacy executables that also depend on a shell profile to setup env vars properly. Is there a way to exec this profile using ant in the current process so the makefiles ant calls get the env vars correctly?
Another solution would be if there is a way to add the profile sourcing to the sub make files I'm calling.
Edit: I guess I wasn't clear in my question. I know what env varibles need to be passed to make using the exec/env tasks. However, I don't know how to have ant grab the values from a shell profile that is usually sourced via: . /usr/local/profile/foo.profile
I figured out how to do it based off of how ant itself sources env variables.
<exec executable="ksh" dir="${foo.dir}"
failonerror="true" output="${foo.dir}/env.properties">
<arg value="-c" />
<arg value=". /usr/local/profiles/profile.foo; set" />
</exec>
<property file="${foo.dir}/env.properties" prefix="env"/>
Further down I can then pass them to sub make calls using the exec tags. For example:
<exec executable="make" dir="${bar.dir}" failonerror="true">
<env key="ORACLE_HOME" value="${env.ORACLE_HOME}" />
</exec>
You will not be able to execute make in the current process.
Take a look at the ant <exec> task, use this to execute your make build. The environment variables will still be available for the make process, in fact you can turn this off explicitly with the newenvironment attribute. The following simple exec should retain all environment variables in make:
<exec executable="make" />
If you need extra environment variables, or want to maintain them through your ant build you can use them in the exec task by adding <env> elements like so:
<exec executable="make" >
<env key="ENV_KEY" value="ENV_VALUE"/>
</exec>