You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by David Forslund <dw...@lanl.gov> on 2000/07/24 22:56:48 UTC

Classpath issues

I want to use a classpath from ant and send it on as a argument of a 
separate program that is being executed.
It could be set as an environment variable for that task (under exec), but 
I don't see how to set an environment variable for an exec task.  The 
problem is that I can build up a classpath, but it will have "\" and "/" in 
it.  When the
task is executed by ant, all the "\" are removed (I guess they are simply 
taken as passing the next literal through).  As a result the classpath 
argument is completely incorrect and my application fails.   How can I get 
Ant to pass
through the classpath literally (or better, make sure that it has proper 
classpath syntax).  The <classpath /> item doesn't work in this case 
because it isn't an explicit argument of the exec task.

Any suggestions as to how to do this correctly, would be greatly appreciated.

David W. Forslund                               dwf@lanl.gov
Advanced Computing Laboratory           http://www.acl.lanl.gov/~dwf
Los Alamos National Laboratory          Los Alamos, NM 87545
505-665-1907                                    FAX: 505-665-4939


Re: Classpath issues

Posted by Stefan Bodewig <bo...@bost.de>.
>>>>> "JC" == Julien Couvreur <jc...@redcart.com> writes:

 JC> Why isn't the "path" just a "value" ?

Because you are free to use : and ; as path separators freely in Ant
but need to convert it to the OS convention when using it as a value
of an environment variable.

Ant needs to know it is a PATH like thing - you wouldn't want it to
replace all colons by semicolons on Windows for arbitrary variables.

Stefan

RE: Classpath issues

Posted by Julien Couvreur <jc...@redcart.com>.
Hi,

Thanks for implementing this feature, that we were discussing a couple weeks
ago !

I now use it and am very happy with it (except for the "not passing the
system env variables as a default").

One thing that wonders me though is why this issue is related to "Classpath"
! This appears in the title of this discussion, and also because a "path" is
associated with the "key".

Why isn't the "path" just a "value" ?

Thanks again,
Julien


Re: Classpath issues

Posted by James Duncan Davidson <du...@x180.com>.
on 7/26/00 2:21 AM, Stefan Bodewig at bodewig@bost.de wrote:

>>>>>> "DWF" == David W Forslund <dw...@lanl.gov> writes:
> 
> DWF> Indeed, this is the case.  I can get the PATH environment from
> DWF> the java.library.path property.  When I set my PATH to that, it
> DWF> all works.  This is not a problem, but something one must be
> DWF> aware of.
> 
> Is this documented anywhere? The list of properties that are "always
> included" in the javadocs to System.getProperties doesn't list it.

The almanac lists them -- but they do vary from place to place with the
props that each VM person throws in. Seems like I write something like the
following every once in a while just to see what's local (and this isn't
tested code!)

import java.util.*

public class SysPropsLister {

    public static void main(String[] args) {
        Properties props = System.getProperties();
        props.save(System.out, "System Properties Dump);
    }
}


Re: Classpath issues

Posted by Stefan Bodewig <bo...@bost.de>.
>>>>> "DWF" == David W Forslund <dw...@lanl.gov> writes:

 DWF> Indeed, this is the case.  I can get the PATH environment from
 DWF> the java.library.path property.  When I set my PATH to that, it
 DWF> all works.  This is not a problem, but something one must be
 DWF> aware of.

Is this documented anywhere? The list of properties that are "always
included" in the javadocs to System.getProperties doesn't list it.

Stefan

Re: Classpath issues

Posted by David W Forslund <dw...@lanl.gov>.
Louis Tribble writes:
 > David Forslund wrote:
 > > 
 > > Thanks for doing this!   It seems that if I set CLASSPATH this way then I
 > > lose my PATH environment variable.
 > > It seems that if I set one environment variable, I need to set them
 > > all.   Is this how you see it working?
 > 
 > I can't speak for the _wishes_ of the Ant developers, but that behavior
 > is inherited from Runtime.exec(): if you omit the envp argument, the 
 > current environment is passed to the subprocess; if you do, only the 
 > name-value pairs you actually specify are passed.
 > 
 > I can't think of a decent portable way to do better, but making the
 > required environment variables explicit seems like better style anyways.
 >

Indeed, this is the case.  I can get the PATH environment from
the java.library.path property.  When I set my PATH to that, it all
works.  This is not a problem, but something one must be aware of. 

 > It might help some people if the ant scripts on platforms where it makes 
 > sense (Windows, Unix) passed PATH in as a system property so it's 
 > available for passing to subprocesses.
 >
thanks,

Dave
 > Louis Tribble
 > -- 
 > 
 > <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
 > Louis Tribble                                         louis@metamata.com
 > Metamata, Inc.                                   http://www.metamata.com
 > Tools for serious Java developers.                       +1 510 796 0915
 > <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>

Re: Classpath issues

Posted by Louis Tribble <lo...@metamata.com>.
David Forslund wrote:
> 
> Thanks for doing this!   It seems that if I set CLASSPATH this way then I
> lose my PATH environment variable.
> It seems that if I set one environment variable, I need to set them
> all.   Is this how you see it working?

I can't speak for the _wishes_ of the Ant developers, but that behavior
is inherited from Runtime.exec(): if you omit the envp argument, the 
current environment is passed to the subprocess; if you do, only the 
name-value pairs you actually specify are passed.

I can't think of a decent portable way to do better, but making the
required environment variables explicit seems like better style anyways.

It might help some people if the ant scripts on platforms where it makes 
sense (Windows, Unix) passed PATH in as a system property so it's 
available for passing to subprocesses.

Louis Tribble
-- 

<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
Louis Tribble                                         louis@metamata.com
Metamata, Inc.                                   http://www.metamata.com
Tools for serious Java developers.                       +1 510 796 0915
<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>

RE: Classpath issues

Posted by David Forslund <dw...@lanl.gov>.
Thanks for doing this!   It seems that if I set CLASSPATH this way then I 
lose my PATH environment variable.
It seems that if I set one environment variable, I need to set them 
all.   Is this how you see it working?

Thanks,

Dave
At 12:17 AM 7/26/00 +1000, you wrote:
>David,
>
>It is there now. You can try
>
>     <target name="exectest">
>         <exec command="exectest.bat" dir=".">
>           <env key="ANT_TEST" path="../test:../test2"/>
>         </exec>
>     </target>
>
>to set the ANT_TEST environment variable to a classpath.
>
>Conor
>
>
> > -----Original Message-----
> > From: David Forslund [mailto:dwf@lanl.gov]
> > Sent: Tuesday, 25 July 2000 12:33
> > To: ant-dev@jakarta.apache.org
> > Subject: RE: Classpath issues
> >
> >
> > This sounds great, but I can't see in the documentation as to how to
> > utilize the Environment class.
> >
> > Thanks,
> >
> > Dave
> > At 11:59 AM 7/25/00 +1000, you wrote:
> > >I made a little change regarding this but I haven't committed it yet. I
> > >simply added a setPath method to the Environment.Variable class
> > so that you
> > >could pass a patform specific path (classpath) from a
> > platform-independent
> > >build file.
> > >
> > >--
> > >Conor MacNeill
> > >conor@cortexebusiness.com.au
> > >Cortex eBusiness
> > >http://www.cortexebusiness.com.au
> > >
> > > > -----Original Message-----
> > > > From: David Forslund [mailto:dwf@lanl.gov]
> > > > Sent: Tuesday, 25 July 2000 6:57
> > > > To: ant-dev@jakarta.apache.org
> > > > Subject: Classpath issues
> > > >
> > > >
> > > > I want to use a classpath from ant and send it on as a argument of a
> > > > separate program that is being executed.
> > > > It could be set as an environment variable for that task (under
> > > > exec), but
> > > > I don't see how to set an environment variable for an exec task.  The
> > > > problem is that I can build up a classpath, but it will have "\"
> > > > and "/" in
> > > > it.  When the
> > > > task is executed by ant, all the "\" are removed (I guess
> > they are simply
> > > > taken as passing the next literal through).  As a result the classpath
> > > > argument is completely incorrect and my application fails.   How
> > > > can I get
> > > > Ant to pass
> > > > through the classpath literally (or better, make sure that it
> > has proper
> > > > classpath syntax).  The <classpath /> item doesn't work in this case
> > > > because it isn't an explicit argument of the exec task.
> > > >
> > > > Any suggestions as to how to do this correctly, would be greatly
> > > > appreciated.
> > > >
> > > > David W. Forslund                               dwf@lanl.gov
> > > > Advanced Computing Laboratory           http://www.acl.lanl.gov/~dwf
> > > > Los Alamos National Laboratory          Los Alamos, NM 87545
> > > > 505-665-1907                                    FAX: 505-665-4939
> > > >
> > > >
> >
> >


RE: Classpath issues

Posted by Conor MacNeill <co...@cortexebusiness.com.au>.
OK,

Unless someone else objects, I'll commit the patch and give a quick example
of how to use tonight.

Conor


--
Conor MacNeill
conor@cortexebusiness.com.au
Cortex eBusiness
http://www.cortexebusiness.com.au

> -----Original Message-----
> From: David Forslund [mailto:dwf@lanl.gov]
> Sent: Tuesday, 25 July 2000 12:33
> To: ant-dev@jakarta.apache.org
> Subject: RE: Classpath issues
>
>
> This sounds great, but I can't see in the documentation as to how to
> utilize the Environment class.
>
> Thanks,
>
> Dave
> At 11:59 AM 7/25/00 +1000, you wrote:
> >I made a little change regarding this but I haven't committed it yet. I
> >simply added a setPath method to the Environment.Variable class
> so that you
> >could pass a patform specific path (classpath) from a
> platform-independent
> >build file.
> >
> >--
> >Conor MacNeill
> >conor@cortexebusiness.com.au
> >Cortex eBusiness
> >http://www.cortexebusiness.com.au
> >
> > > -----Original Message-----
> > > From: David Forslund [mailto:dwf@lanl.gov]
> > > Sent: Tuesday, 25 July 2000 6:57
> > > To: ant-dev@jakarta.apache.org
> > > Subject: Classpath issues
> > >
> > >
> > > I want to use a classpath from ant and send it on as a argument of a
> > > separate program that is being executed.
> > > It could be set as an environment variable for that task (under
> > > exec), but
> > > I don't see how to set an environment variable for an exec task.  The
> > > problem is that I can build up a classpath, but it will have "\"
> > > and "/" in
> > > it.  When the
> > > task is executed by ant, all the "\" are removed (I guess
> they are simply
> > > taken as passing the next literal through).  As a result the classpath
> > > argument is completely incorrect and my application fails.   How
> > > can I get
> > > Ant to pass
> > > through the classpath literally (or better, make sure that it
> has proper
> > > classpath syntax).  The <classpath /> item doesn't work in this case
> > > because it isn't an explicit argument of the exec task.
> > >
> > > Any suggestions as to how to do this correctly, would be greatly
> > > appreciated.
> > >
> > > David W. Forslund                               dwf@lanl.gov
> > > Advanced Computing Laboratory           http://www.acl.lanl.gov/~dwf
> > > Los Alamos National Laboratory          Los Alamos, NM 87545
> > > 505-665-1907                                    FAX: 505-665-4939
> > >
> > >
>
>


RE: Classpath issues

Posted by Conor MacNeill <co...@m64.com>.
David,

It is there now. You can try

    <target name="exectest">
        <exec command="exectest.bat" dir=".">
          <env key="ANT_TEST" path="../test:../test2"/>
        </exec>
    </target>

to set the ANT_TEST environment variable to a classpath.

Conor


> -----Original Message-----
> From: David Forslund [mailto:dwf@lanl.gov]
> Sent: Tuesday, 25 July 2000 12:33
> To: ant-dev@jakarta.apache.org
> Subject: RE: Classpath issues
>
>
> This sounds great, but I can't see in the documentation as to how to
> utilize the Environment class.
>
> Thanks,
>
> Dave
> At 11:59 AM 7/25/00 +1000, you wrote:
> >I made a little change regarding this but I haven't committed it yet. I
> >simply added a setPath method to the Environment.Variable class
> so that you
> >could pass a patform specific path (classpath) from a
> platform-independent
> >build file.
> >
> >--
> >Conor MacNeill
> >conor@cortexebusiness.com.au
> >Cortex eBusiness
> >http://www.cortexebusiness.com.au
> >
> > > -----Original Message-----
> > > From: David Forslund [mailto:dwf@lanl.gov]
> > > Sent: Tuesday, 25 July 2000 6:57
> > > To: ant-dev@jakarta.apache.org
> > > Subject: Classpath issues
> > >
> > >
> > > I want to use a classpath from ant and send it on as a argument of a
> > > separate program that is being executed.
> > > It could be set as an environment variable for that task (under
> > > exec), but
> > > I don't see how to set an environment variable for an exec task.  The
> > > problem is that I can build up a classpath, but it will have "\"
> > > and "/" in
> > > it.  When the
> > > task is executed by ant, all the "\" are removed (I guess
> they are simply
> > > taken as passing the next literal through).  As a result the classpath
> > > argument is completely incorrect and my application fails.   How
> > > can I get
> > > Ant to pass
> > > through the classpath literally (or better, make sure that it
> has proper
> > > classpath syntax).  The <classpath /> item doesn't work in this case
> > > because it isn't an explicit argument of the exec task.
> > >
> > > Any suggestions as to how to do this correctly, would be greatly
> > > appreciated.
> > >
> > > David W. Forslund                               dwf@lanl.gov
> > > Advanced Computing Laboratory           http://www.acl.lanl.gov/~dwf
> > > Los Alamos National Laboratory          Los Alamos, NM 87545
> > > 505-665-1907                                    FAX: 505-665-4939
> > >
> > >
>
>


RE: Classpath issues

Posted by David Forslund <dw...@lanl.gov>.
This sounds great, but I can't see in the documentation as to how to 
utilize the Environment class.

Thanks,

Dave
At 11:59 AM 7/25/00 +1000, you wrote:
>I made a little change regarding this but I haven't committed it yet. I
>simply added a setPath method to the Environment.Variable class so that you
>could pass a patform specific path (classpath) from a platform-independent
>build file.
>
>--
>Conor MacNeill
>conor@cortexebusiness.com.au
>Cortex eBusiness
>http://www.cortexebusiness.com.au
>
> > -----Original Message-----
> > From: David Forslund [mailto:dwf@lanl.gov]
> > Sent: Tuesday, 25 July 2000 6:57
> > To: ant-dev@jakarta.apache.org
> > Subject: Classpath issues
> >
> >
> > I want to use a classpath from ant and send it on as a argument of a
> > separate program that is being executed.
> > It could be set as an environment variable for that task (under
> > exec), but
> > I don't see how to set an environment variable for an exec task.  The
> > problem is that I can build up a classpath, but it will have "\"
> > and "/" in
> > it.  When the
> > task is executed by ant, all the "\" are removed (I guess they are simply
> > taken as passing the next literal through).  As a result the classpath
> > argument is completely incorrect and my application fails.   How
> > can I get
> > Ant to pass
> > through the classpath literally (or better, make sure that it has proper
> > classpath syntax).  The <classpath /> item doesn't work in this case
> > because it isn't an explicit argument of the exec task.
> >
> > Any suggestions as to how to do this correctly, would be greatly
> > appreciated.
> >
> > David W. Forslund                               dwf@lanl.gov
> > Advanced Computing Laboratory           http://www.acl.lanl.gov/~dwf
> > Los Alamos National Laboratory          Los Alamos, NM 87545
> > 505-665-1907                                    FAX: 505-665-4939
> >
> >


RE: Classpath issues

Posted by Conor MacNeill <co...@cortexebusiness.com.au>.
I made a little change regarding this but I haven't committed it yet. I
simply added a setPath method to the Environment.Variable class so that you
could pass a patform specific path (classpath) from a platform-independent
build file.

--
Conor MacNeill
conor@cortexebusiness.com.au
Cortex eBusiness
http://www.cortexebusiness.com.au

> -----Original Message-----
> From: David Forslund [mailto:dwf@lanl.gov]
> Sent: Tuesday, 25 July 2000 6:57
> To: ant-dev@jakarta.apache.org
> Subject: Classpath issues
>
>
> I want to use a classpath from ant and send it on as a argument of a
> separate program that is being executed.
> It could be set as an environment variable for that task (under
> exec), but
> I don't see how to set an environment variable for an exec task.  The
> problem is that I can build up a classpath, but it will have "\"
> and "/" in
> it.  When the
> task is executed by ant, all the "\" are removed (I guess they are simply
> taken as passing the next literal through).  As a result the classpath
> argument is completely incorrect and my application fails.   How
> can I get
> Ant to pass
> through the classpath literally (or better, make sure that it has proper
> classpath syntax).  The <classpath /> item doesn't work in this case
> because it isn't an explicit argument of the exec task.
>
> Any suggestions as to how to do this correctly, would be greatly
> appreciated.
>
> David W. Forslund                               dwf@lanl.gov
> Advanced Computing Laboratory           http://www.acl.lanl.gov/~dwf
> Los Alamos National Laboratory          Los Alamos, NM 87545
> 505-665-1907                                    FAX: 505-665-4939
>
>