ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mike Spross" <mgspr...@gmail.com>
Subject Re: Storing all libs in SCM?
Date Tue, 03 Jun 2008 04:31:44 GMT
On Mon, Jun 2, 2008 at 3:45 PM, Tim Visher <tim.visher@gmail.com> wrote:

> I've gotten things to work by putting the necessary lib files in
> ANT_HOME/lib and by using the -lib flag to specify an alternate
> location that also has the necessary lib files, but I can't figure out
> how to pass something like the -lib option internally to the build.xml
> file.

You can tell Eclipse to run a custom Ant build script by creating a
custom builder task: go to the project's properties, select Builders,
click New, and select Ant Builder. You can point Eclipse to an Ant
script to run and specify additional command-line arguments to pass to
Ant. The builder will run whenever you build the parent project in
Eclipse. However, I already tried this, and it appears that Eclipse's
built-in Ant doesn't support the -lib flag anyway; you have to add
explicitly add every JAR you need in the Classpath tab, or dynamically
build the classpath in the Ant script that you are running. I'm not
sure if there is a cleaner way to handle all this, but off the top of
my head here are some possible workarounds (haven't tested any of
these ideas), that are all basically the same concept, but slightly
different variations:

1) Make a stub launch-build.xml file that only Eclipse uses. This file
would invoke the standalone version of ant, passing it the real
build.xml file and the correct lib path, since the standalone version
of Ant can handle the -lib flag properly.

2) Have a single build.xml file that dynamically builds the classpath
by scanning some path that we could define in an Ant variable.

3) Create a new Builder in Eclipse using the Program option, instead
of the Ant Builder option. The builder invokes the standalone version
of Ant, passing in the correct lib path via the -lib flag. Like option
2, we would only need one build.xml file.

In any case, I'm not sure how we can get around the problem of
duplicating classpath information. That is, the Eclipse projects have
their own classpath settings, but then so will the Ant build scripts
that we create. Unless there is some way to keep the two in sync
without manually having to edit one when the other changes.

> I've tried specifying the classpath property in the javac task
> but that did not work either, even though when I ran ant in -verbose
> mode the classpath option that was apparently being passed to javac
> did have the correct folder on it.

I created a HelloWorld class that uses the javax.persistence package,
which is in javaee.jar, and a build.xml that just runs javac with the
classpath pointing to javee.jar on my system. The classpath setting
worked fine for me, so I have to ask the obvious question here: did
you remember to put the full path to the .jar file(s) in classpath, as
opposed to just the folder path? Here are HelloWorld.java and
build.xml:

~/HelloWorld/src/HelloWorld.java:

import javax.persistence.*;

@Entity //just to use something in javaee.jar...
public class HelloWorld {
	public static void main(String[] args) {
		System.out.println("Hello world!");
	}
}

~/HelloWorld/build.xml:

<project>
	<javac
		srcdir="src"
		destdir="build"
		classpath="/opt/jee_sdk/lib/javaee.jar"
		debug="on"
	/>
</project>


-- 
Mike Spross

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message