You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Luke Taylor <ne...@freesurf.ch> on 2000/11/17 11:36:00 UTC

broken build problem with relative path to ant.jar

Hi,

I've recently switched to using ant 1.2 and have come across problems
with the build for jBoss (the EJB server) and similar builds from the
project. They have the ant.jar file included  in <basedir>/lib to allow
them to build independently of any installation, and this file is added
along with the parser etc. to the classpath that is used when running
the ant program i.e

set CP=..\..\lib\ant.jar
set CP=%CP%;..\..\lib\xml.jar
set CP=%CP%;..\..\lib\javac.jar

java -classpath "%CP%" org.apache.tools.ant.Main %1 %2 %3 %4 %5

This works OK with previous versions of ant, but the javac command
results in an error with v 1.2 (and the current nightly build):

The file or path you specified (..\..\lib\ant.jar) is invalid releative
(sic :-) to H:\jBoss

So it seems to be trying to make use of the classpath use to run ant,
and tring to resolve it relative to the basedir, rather than the
directory from which the script was run. I guess using NT isn't helping
things either :-(.

Any suggestions on what might be causing this and how I can get it to
work?

Thanks,

Luke.



-- 
 Luke Taylor.
 PGP Key ID: 0x57E9523C

Re: broken build problem with relative path to ant.jar

Posted by Bill Burton <bi...@progress.com>.
Hello,

There are several issues with the script you are using to start Ant.  I'm
not familiar with jBoss so there are certain assumptions I'm making about
the directory structure that may not be correct ...

Luke Taylor wrote:
> 
> Hi,
> 
> I've recently switched to using ant 1.2 and have come across problems
> with the build for jBoss (the EJB server) and similar builds from the
> project. They have the ant.jar file included  in <basedir>/lib to allow
> them to build independently of any installation, and this file is added
> along with the parser etc. to the classpath that is used when running
> the ant program i.e
> 
> set CP=..\..\lib\ant.jar
> set CP=%CP%;..\..\lib\xml.jar
> set CP=%CP%;..\..\lib\javac.jar
> 
> java -classpath "%CP%" org.apache.tools.ant.Main %1 %2 %3 %4 %5

This doesn't set the property ant.home.  For instance, in the ant.bat
script included with Ant 1.2, you will find:
    -Dant.home="%ANT_HOME%"
on the command line to run Ant.  The ant.bat script tries to guess where
Ant is installed and will not run if it cannot make this determination.

> This works OK with previous versions of ant, but the javac command
> results in an error with v 1.2 (and the current nightly build):
> 
> The file or path you specified (..\..\lib\ant.jar) is invalid releative
> (sic :-) to H:\jBoss

You could make the following changes to get around this:

In H:\jBoss create a batch file called gethome.bat with the following
lines:
  rem Set this to where jBoss is installed
  set JBOSS_HOME=H:\jBoss

Then modify the build.bat and any other scripts that need to know the
jBoss installation directory do this:
  if exist ..\..\gethome.bat call ..\..\gethome
  if x%JBOSS_HOME%==x goto NOHOME

  set CP=%JBOSS_HOME%\lib\ant.jar
  set CP=%CP%;%JBOSS_HOME%\lib\xml.jar
  set CP=%CP%;%JBOSS_HOME%\lib\xmlbeans.jar
  set CP=%CP%;%JBOSS_HOME%\build\classes
  set CP=%CP%;%JBOSS_HOME%\lib\javac.jar

  java -classpath "%CP%" -Dant.home=%JBOSS_HOME% org.apache.tools.ant.Main
%1 %2 %3 %4 %5
  goto EOF

  :NOHOME
  echo ERROR: JBOSS_HOME was not set to the installation directory

  :EOF

In case you are wondering, there is no obvious "pwd" equivalent you can
call in a .bat file.  The "cd" command with no arguments echos the current
directory but there's no obvious way you can't set a variable from it. 
However, I just discovered there is a way to save the current directory
into a variable on Windows NT/2000 only, not 95/98. 
  rem set pwd to the current directory
  for /f %%i in ('cd') do set pwd=%%i
so the above is the equivalent of pwd=`pwd` or pwd=$(pwd) on UNIX.  So you
could now use %pwd% to set CP.  However, it's still probably better to set
JBOSS_HOME explicitly and use that.

A better option might be to install a full copy of Ant 1.2 in it's own
directory instead of trying to merge parts of Ant into the jBoss tree
(which I assume you're doing).  Then in NT's My Computer, Environment,
create a User Variable ANT_HOME pointing to the location where Ant is
installed.  This will take effect on any new MS-DOS command prompt windows
you open.  To do builds, run ant.bat in the Ant distribution instead of
the build.bat in jBoss.

Hope this helps,
-Bill

> So it seems to be trying to make use of the classpath use to run ant,
> and tring to resolve it relative to the basedir, rather than the
> directory from which the script was run. I guess using NT isn't helping
> things either :-(.
> 
> Any suggestions on what might be causing this and how I can get it to
> work?
> 
> Thanks,
> 
> Luke.
> 
> --
>  Luke Taylor.
>  PGP Key ID: 0x57E9523C

-- 
Bill Burton, Senior Internet Software Engineer
E-mail: billb@progress.com
Progress Software Corporation

Re: broken build problem with relative path to ant.jar

Posted by Stefan Bodewig <bo...@apache.org>.
Luke Taylor <ne...@freesurf.ch> wrote:

> Stefan Bodewig wrote:
>> 
>> Luke Taylor <ne...@freesurf.ch> wrote:
>> 
>> > So it seems to be trying to make use of the classpath use to run
>> > ant, and tring to resolve it relative to the basedir,
>> 
>> yes, that is exactly what is happening. The content of
>> java.class.path is appended to the CLASSPATH that javac is invoked
>> with.
>>
> 
> Is this the case even when using the "classpath" argument with javac
> (which the build file does) ?

Yes. Whatever you specify is added to the classpath but the system
classpath will be in there as well.

>> > Any suggestions on what might be causing this and how I can get
>> > it to work?
>> 
>> Not using relative paths in your scripts that invoke Ant?

> I suppose an alternative would be to use the windows equivalent of
> "pwd" in the script and use that to set the classpath, but I don't
> know enough about windows scripting (apart from the fact that it's
> pretty lousy).

I'm in the same position, I *think* it should be possible but don't
know enough about the .bat language or the OS it's being used on.

Stefan

Re: broken build problem with relative path to ant.jar

Posted by Luke Taylor <ne...@freesurf.ch>.
Hi,

Thanks for your speedy response.

Stefan Bodewig wrote:
> 
> Luke Taylor <ne...@freesurf.ch> wrote:
> 
> > So it seems to be trying to make use of the classpath use to run
> > ant, and tring to resolve it relative to the basedir,
> 
> yes, that is exactly what is happening. The content of java.class.path
> is appended to the CLASSPATH that javac is invoked with.
>

Is this the case even when using the "classpath" argument with javac
(which the build file does) ?
 
> Ant doesn't really see that you've specified this path outside the
> build file and Ant now always interprets a relative path as being
> relative to the project's basedir. Wherever it finds one.
> 
> > Any suggestions on what might be causing this and how I can get it
> > to work?
> 
> Not using relative paths in your scripts that invoke Ant?
> 
> I don't know whether this is an option for you. Maybe set an
> environment variable that points to the directory containing the jar
> files and use ${BASE}/javac.jar in the CLASSPATH?
> 

It's not a big deal 'cos it works fine if you have ant installed on
your machine and just run it directly. But it is nice for people who
don't know anything about ant to be able to download a set of files
from an open source project and do a complete build just by running the
script and without having to set any variables or paths specific to
their own machine. I suppose an alternative would be to use the windows
equivalent of "pwd" in the script and use that to set the classpath,
but I don't know enough about windows scripting (apart from the fact
that it's pretty lousy).

Cheers,

Luke.



-- 
 Luke Taylor.
 PGP Key ID: 0x57E9523C

Re: broken build problem with relative path to ant.jar

Posted by Stefan Bodewig <bo...@apache.org>.
Luke Taylor <ne...@freesurf.ch> wrote:

> So it seems to be trying to make use of the classpath use to run
> ant, and tring to resolve it relative to the basedir,

yes, that is exactly what is happening. The content of java.class.path
is appended to the CLASSPATH that javac is invoked with.

Ant doesn't really see that you've specified this path outside the
build file and Ant now always interprets a relative path as being
relative to the project's basedir. Wherever it finds one.

> Any suggestions on what might be causing this and how I can get it
> to work?

Not using relative paths in your scripts that invoke Ant? 

I don't know whether this is an option for you. Maybe set an
environment variable that points to the directory containing the jar
files and use ${BASE}/javac.jar in the CLASSPATH?

Stefan