ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject RE: setting classpath in a build.xml file
Date Tue, 12 Aug 2003 05:50:14 GMT
> Hi,
> 	I've just started using ANT so please be kind to my 
> stupid questions :)

Don´t worry about that. If you read the manual and don´t find the answer
all here will help you :-)

> During the build I'm trying to test to see if a supplied environment 
> variable is valid. I know it is valid if a a class can be found in a
> related jar found in a subdirectory called classes.
> So I'm trying to do this with the following :
> <target name="init">
>    <!-- here I'm setting up my class path to test it -->
>    <path id="ooo.classpath">
>      <fileset dir="${env.OOO_PATH}/classes">

The 'env.' clause let me think that you want to access environment
Therefore the statement
    <property environment="env"/>
must be executed before that (inside the init target or outside of all
targets = directly under <project>).

>        <include name="**/*.jar"/>

Usually you haven´t any JAR files under a /classes directory. Usually (maybe
not in your development environment) there is a /classes directory
the *.class files and a /lib directory containing the *.jar files.

>      </fileset>
>      <pathelement location="classes"/>
>    </path>

Little test: print out the result of ooo.classpath.
    <pathconvert property="test" refid="ooo.classpath"
pathsep="${line.separator}- "/>
    <echo message="ooo.classpath contains:"/>
    <echo message="- ${test}"/>
Should output something like
    [echo] ooo.classpath contains:
    [echo] - c:\bla\blub\classes\xy.jar
    [echo] - c:\bla\blub\classes\subdir\foo.jar
    [echo] - c:\bla\blub\classes\subdir2\bar.jar

>    <!-- Ant does not seem to like this! -->
>    <classpath>
>      <pathelement path="${classpath}"/>
>      <path refid="ooo.classpath"/>
>    </classpath>

Can´t see any error. Maybe you <echo> the ${classpath} ... And you are
referencing ooo.classpath,
so it could be the error has its origin some lines earlier ...

>    <!-- is this the correct way to do such a test ? -->
>    <condition property="no_ooo_path">
>        <not><available 
> classname="">
>        </not>
>    </condition>


>    <echo message="OOO_PATH is set to : ${env.OOO_PATH}"/>
>    <!-- report a problem if the no_ooo_path property has been set! -->
>    <fail if="no_ooo_path"
>        message="you need to specify the environment variable
>        OOO_PATH to point to the OpenOffice/program directory"/>

Seems to be ok.

> </target>
> You'll see from the comments above that I have some problems.
> But is  this the correct way to do this ?

Print out some values (see above). Start Ant with -verbose mode.

> What I'd also like is to have my classpath setup at the 
> toplevel so that 
> it will automatically be setup for all targets.

Do that outside of <target>s. Outside of targets you can have
<property>, <path>, ... (äh) ... some more.
With Ant 1.6 (only as CVS version at this time) you can have all elements
outside of targets. 
Elements outside of targets are executed before the first target is called.

> Thanks for any help,
> Con Hennessy
> P.S. Please CC: me as I am not subscribed.

No, no, no....
Wrong way - do that :-)
If you start a discussion on the list the discussion will keep here.


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message