You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@buildr.apache.org by Mark Petrovic <ms...@gmail.com> on 2010/09/09 07:15:34 UTC

Executing Ant build scripts

I have a TestApp project located under trunk/ thusly:

trunk/
	testapps/
		TestApp/

TestApp is actually a NetBeans project that has a NB-generated Ant build file.

Given this buildfile fragment

    desc "TestApp"
    define "TestApp" do
      task :buildme do
        Java.classpath << artifact("org.apache.ant:ant-nodeps:jar:1.8.0")
        Java.classpath << artifact("org.apache.ant:ant-junit:jar:1.8.0")
        Java.org.apache.tools.ant.Main.main(['-f', _("build.xml"), 'default'])
      end
      compile :buildme
    end


and this set of commands

$ pwd 
trunk
$ cd testapps/TestApp
$ buildr clean package

I find the build of TestApp succeeds.

However, if I cd ../.. to trunk/ and execute

$ buildr clean package

I get

BUILD FAILED
/Users/petrovic/f/trunk/testapps/TestApp/nbproject/build-impl.xml:501: Problem: failed to create task or type propertyfile
Cause: the class org.apache.tools.ant.taskdefs.optional.PropertyFile was not found.
        This looks like one of Ant's optional components.
Action: Check that the appropriate optional JAR exists in
        -ANT_HOME/lib
        -the IDE Ant configuration dialogs

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



where org.apache.tools.ant.taskdefs.optional.PropertyFile is in ant-nodeps.jar.

Any idea why the build succeeds in the TestApp directory, but not two levels up in the trunk?



--
Mark Petrovic



Re: Executing Ant build scripts

Posted by Antoine Toulme <an...@lunar-ocean.com>.
Yes for antwrap.

And if you do anything with the classpath, do it before you define anything.

On Wed, Sep 8, 2010 at 22:38, Peter Donald <pe...@realityforge.org> wrote:

> > Given this buildfile fragment
> >
> >    desc "TestApp"
> >    define "TestApp" do
> >      task :buildme do
> >        Java.classpath << artifact("org.apache.ant:ant-nodeps:jar:1.8.0")
> >        Java.classpath << artifact("org.apache.ant:ant-junit:jar:1.8.0")
> >        Java.org.apache.tools.ant.Main.main(['-f', _("build.xml"),
> 'default'])
> >      end
> >      compile :buildme
> >    end
> >
> > Any idea why the build succeeds in the TestApp directory, but not two
> levels up in the trunk?
>
> You have hit one one of the most annoying things about buildr.
> Java.classpath will add to the classpath if Java.init has not be
> called and Java.init is called the first time someone wants to
> instantiate a java class. So whether a Java.classpath succeeds in
> adding a file to classpath is completely dependent on the extension
> you installed, the files you require and the nesting level of projects
> etc. It also seems to randomly change between releases.
>
> The take away from this is that you should never use it if you want a
> reproducible build. I experimented with using the Java module to
> instantiate a URLClassLoader and adding to that but in the end I ended
> up deciding that it was easier to just use command line apps.
>
> However if what you want to do is interact with ant I would recommend
> using the antwrap feature of buildr. You can see examples of it in the
> addon directory or look at some documentation at
> http://antwrap.rubyforge.org/
>
>
> --
> Cheers,
>
> Peter Donald
>

Re: Executing Ant build scripts

Posted by Peter Donald <pe...@realityforge.org>.
> Given this buildfile fragment
>
>    desc "TestApp"
>    define "TestApp" do
>      task :buildme do
>        Java.classpath << artifact("org.apache.ant:ant-nodeps:jar:1.8.0")
>        Java.classpath << artifact("org.apache.ant:ant-junit:jar:1.8.0")
>        Java.org.apache.tools.ant.Main.main(['-f', _("build.xml"), 'default'])
>      end
>      compile :buildme
>    end
>
> Any idea why the build succeeds in the TestApp directory, but not two levels up in the trunk?

You have hit one one of the most annoying things about buildr.
Java.classpath will add to the classpath if Java.init has not be
called and Java.init is called the first time someone wants to
instantiate a java class. So whether a Java.classpath succeeds in
adding a file to classpath is completely dependent on the extension
you installed, the files you require and the nesting level of projects
etc. It also seems to randomly change between releases.

The take away from this is that you should never use it if you want a
reproducible build. I experimented with using the Java module to
instantiate a URLClassLoader and adding to that but in the end I ended
up deciding that it was easier to just use command line apps.

However if what you want to do is interact with ant I would recommend
using the antwrap feature of buildr. You can see examples of it in the
addon directory or look at some documentation at
http://antwrap.rubyforge.org/


-- 
Cheers,

Peter Donald