Handling PermGen errors in ant bpelc task - ant

I've been hitting a java.lang.OutOfMemoryError: PermGen error when compiling a project with ant under Linux with jdk 1.5.0_11. the same project compiles under windows without problem.
Usually this relates to the MaxPermSize allocated to the JVM. Irakli Nadareishvili has one of the best explanations of PermGen errors and guide to setting Java HotSpot VMOptions (e.g. -XX:MaxPermSize=128M)
In this case, I quickly narrowed the issue down to a particular bpelc ant task
<bpelc input="${build.dir}/bpel/bpel.xml"
out="${build.dir}/output" rev="${version}" home="${bpel.home}"/>
Now I don't think bpelc takes the compilerarg element like javac:
<javac srcdir="${src.dir}"
destdir="${classes.dir}"
classpathref="libraries">
<compilerarg value="-XX:MaxPermSize=128M"/>
</javac>
So how to fix the error for the bpelc task? The best solution I've come up with so far is to set the ANT_OPTS environment variable. This seems to have avoided the problem to date.
export ANT_OPTS=-XX:MaxPermSize=128m
Can anyone shed more light? Is that a sure-fire fix?

When the bpelc task executes inside the original JVM running ant, then setting ANT_OPTS (or something equivalent) is the only possible solution.
One such equivalent thing might be to refactor that task to a second ant build file and run that using a separate JVM. Not really nicer, but depending on your environment it might be easier to implement.

Related

Junit5 with ant

I am new in ant and junit5. I went through several examples ant/junit4. But I did not find a normal example with a pair of ant with junit5. With a pair of ant with junit4 everything works fine. I downloaded the files from the official site of the junit5 https://junit.org/junit5/docs/current/user-guide/ (For Ant, check out the junit5-jupiter-starter-ant project.), but even they give an error at the very beginning(screen attached) I will try to fix them one by one, but I don't think that official repo committed with errors. Maybe I'm doing something wrong. Or maybe gurus suggest some other simple sample with ant/junit5.
Thank you in advance.
I try to run the original sources from https://github.com/junit-team/junit5-samples and expected to at least compile them. But I get plenty of errors.
So this post has 2 questions:
errors on the screenshot
ant+juni5 integration in general
To reproduce the exact issues one should have the same environment, which is at least the OS, Java version & Ant version. The example itself seems to be using the Junit5 ConsoleLauncher, which is one of the way to run the tests. Looking at the errors it looks like the issue is in the project itself, because if it cannot find the 'symbol' #Test then the Junit(5?) is simply not present on the classpath. Maybe this can be a hint to the author to trty to dig a bit more into the issue, particularly looking into the dependencies (jars) included.
Now going back to how to run Junit5 test with Ant, I can recall the "JUnitLauncher" that apache suggests: https://ant.apache.org/manual/Tasks/junitlauncher.html . Note that you should be attentive on the dependencies here as well, there are number of Jars to be included (opentest4j, junit-platform-xyz). Note that this also depends on the installation of Ant in the environment, so for example if you get a NoClassDefFound for JUnitLauncher, this can be solved by using the 'up-to-date' version of Ant: https://ant.apache.org/bindownload.cgi . In case of Linux you can place these Jars in home/your_username/.ant/lib directory, where it will be automatically picked up.

Use different JRE/JDK for Ant build

For compilation of my Java code, I would like to know if its possible to use one version of the JRE(rt.jar) and use javac belonging to another version of JDK. If yes, how do we include it in the build.xml in Ant? Thanks in advance!
Yes, you can. You use the executable attribute to specify the exact location of javac you want to use, so you can point to another JDK. And you need to set the fork attribute to yes.
<javac fork="yes" executable="...path.../jdk/bin/javac">

Ant, can't compile The JBoss Transactions JTA 4.2.3.SP7 from jboss.org

I have downloaded The JBoss Transactions JTA 4.2.3.SP7 from jboss.org http://www.jboss.org/jbosstm/downloads/4-2-3-SP7 , it's a first link. It is written using ant, when I try to run this I have multiple error about lacking files, etc. I have suplemmented all of them, but I get another errors about lacking variables in files, etc. Maybe it wasn't the best way to repair it so I've left it.
So, after downloading this package what should I do to run this? Thanks in advance.
So.. the solution is to compile it with ant 1.7.x. Greets.

ant build.xml in SCons

I am making use of a library project which uses ant to build. My project however is using SCons because I need a far more complex build setup. Now I would like to use ant via SCons but NOT impose the problematic CLASSPATH issues and installation that ant requires.
So I am currently thinking of writing a build.xml parser, which turns the ant into SCons tasks.
Does anyone know whether this has been done before?
As far as I can tell there is no such parser in existence, which I partly believe is because there is great difference in how SCons and ant work. Especially when it comes to dependency resolution. It should be possible, but the translated file output will be very little SCons like, quite unreadable and probably quite difficult to maintain. Which pretty much defeats the whole reason to use SCons in the first place.
Since the library already uses ant, it would probably be a good idea to just incorporate the running of ant into SCons. If SCons can use ant, then you won't have to maintain the library build script (unless it is you that maintain the ant also)
Have you seen this: http://geosoft.no/development/android.html? We're also looking at converting an ANT based android build into our over-arching SCONS build and this looks like a good starting point.

junitreport ant task giving java.lang.OutOfMemoryError: Java heap space

I'm running junit tests from an ant script. The tests run successfully so ant moves on to the the junitreport task to create the html report. This task is failing with a java.lang.OutOfMemoryError: Java heap space error.
How can I increase the heap size for this task? Or is there another way to resolve this error?
Some additional information:
It was working fine until I added 40 additional tests
I've had a look at the xml output of the tests and it looks reasonable i.e. it's not full of long error messages.
you can use the ANT_OPTS environment variable to increase the heap size ant uses
This error has been raised in ANT bug 34342. The general consensus is that it's caused by excessive memory consumption in the XSLT used to generate the report, and it WON'T be fixed in ANT.
What has worked for me has been to increase the maximum heap size passed to ant, eg -Xmx3304m. As some of the other answers here mentioned, you can use ANT_OPTS to pass the maximum heap size to ant.
Regarding the actual maximum heap size value, it is recommended that it should be either 1/4th of physical memory or 1GB, whichever is smaller. You may need to go beyond the 1GB limit to avoid this memory error however. See Garbage Collector Ergonomics guide on the Oracle website.
You can use the maxmemory set within junit task itself.
<junit printsummary="yes" fork="true" haltonfailure="no" showoutput="yes" maxmemory="512m">
As the docs explain,
Maximum amount of memory to allocate
to the forked VM. Ignored if fork is
disabled. Note: If you get
java.lang.OutOfMemoryError: Java heap
space in some of your tests then you
need to raise the size like
maxmemory="128m"
The "maxmemory="###m" appears to ONLY work if you use fork, If you aren't using fork (like I am) it doesn't get used, You have to use the ANT_OPTS to change the heap.

Resources