You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Marco Struck <M....@PopNet.de> on 2001/01/02 10:22:14 UTC

script task

hi,

we are able to use the <script> task at last again.
but could somebody tell me which objects I am able to access from script ?

I've seen, that it's possible to access the project object, but what is
about environments,
properties and so on ?!

is it possible to check variables with <script>, instead of this construct:

 <target name="check_customer.name" unless="customer.name">
     <fail message="Error: Missing property customer.name" />
 </target>

 <target name="check_customer.project" unless="customer.project">
    <fail message="Error: Missing property customer.project" />
 </target>

 <target name="check_customer.psi" unless="customer.psi">
    <fail message="Error: Missing property customer.psi" />
 </target>

 <target name="create" depends="check_customer.name, check_customer.project,
check_customer.psi">
       ....



Re: script task

Posted by Nico Seessle <Ni...@epost.de>.
----- Original Message -----
From: "Marco Struck" <M....@PopNet.de>
To: <an...@jakarta.apache.org>
Sent: Tuesday, January 02, 2001 10:22 AM
Subject: script task


> hi,
>
> we are able to use the <script> task at last again.
> but could somebody tell me which objects I am able to access from script ?
>

The following objects are available in the script-context:

- properties, accessible by their names
- user properties, accessible by their names
- targets, accessible by their names
- "references" (elements having an id?) , accessible by their names

(everything is available only if it has an valid java-name (i.e. no dots)

> I've seen, that it's possible to access the project object, but what is
> about environments,
> properties and so on ?!
>
> is it possible to check variables with <script>, instead of this
construct:
>

Should be, since you can call myProject.getProperty('prop1'); ... (replace
myProject with the *real* name of your project). And you can use properties
with dots included if you use it like this.

This is from a "real" build-file:

    <script language="javascript"> <![CDATA[
        var buildNumber =
parseInt(VAMOS50.getProperty('product.build.minor'));
        if (isNaN(buildNumber)) buildNumber = 0;
        buildNumber = buildNumber + 1;
        VAMOS50.setProperty('product.build.minor', buildNumber);
    ]]></script>

Nico





Re: Stupid Windows question

Posted by James Bucanek <su...@gloaming.com>.
At 10:24 AM -0700 1/2/01, James Bucanek wrote:
>But I want to put the ant.jar (and parser.jar, and jaxp.jar, and 
>myTasks.jar) somewhere common.  I've read the notes on class paths 
>on the java.sun.com site, and have tried (1) setting a CLASSPATH 
>environment variable to point to the directory, (2) placing the jars 
>in the \jdk1.3\jre\lib\ext, \jdk1.3\jre\lib, and \jdk1.3\lib 
>directories, (3) specified those directories in the java command 
>options, and (4) combinations of the above (restarting the entire OS 
>between configuration changes, of course).

OK, problem solved.  In trying to debug this problem, I turned on 
-verbose to see where the java tool was reading it's classes from.

Ding!

I was putting my .jar files in /jdk1.3/jre/lib/ext.  WRONG!  Java 
loads it's classes from C:\PROGRAM FILES\JAVASOFT\JRE\1.3\lib\ext!

(Which begs the question: What is the jdk1.1/jre/lib directory for?)

None of the classpath stuff worked at all, but at least my 
application is now happy, which makes me happy.

Sorry to bother everyone,

__________________________________
James Bucanek
<ma...@gloaming.com>


Re: Stupid Windows question

Posted by Bill Burton <bi...@progress.com>.
See below ...

James Bucanek wrote:
> 
> At 2:01 PM -0500 1/2/01, Bill Burton wrote:
> >Hello James,
> >
> >You could try using what is known as "Download Extensions."  This allows
> >one jar file to reference jars elsewhere, normally using a relative
> >reference.
> >
> >Rebuild MyAntTool.jar adding a manifest entry something like this:
> >   Class-Path: ant.jar jaxp.jar parser.jar optional.jar
> >
> >Now, as long as MyAntTool.jar and all these jars listed in the Class-Path
> >directive are located in the same directory, MyAntTool.jar will be able to
> >find them as necessary.  For more information, see
> >http://java.sun.com/docs/books/tutorial/ext/basics/download.html.
> 
> This would work if the ant.jar (etc.) jars were together with my
> application, but I really wanted that kind of stuff to be installed
> as common resources on the workstation, independent of my tool or any
> of my projects.  Well, I can see advantages and disadvantages to both
> ways, and this would certainly make some things easier.  Thanks for
> the tip.

Your MyAntTool.jar doesn't have to look for the other jars in the same
directory.  If it was located in a directory parallel to the Ant
directory, you could use a relative path to each jar:
  Class-Path: ../jakarta-ant/lib/ant.jar ...

Also, some on this list have mentioned checking into their source code
management system the relevent parts of Ant with each project.  That way,
they always have the right version of Ant that can build that project. 
When a new version of Ant comes out, they can then upgrade each project
independently without affecting the others.  This is even more important
if you've written custom tasks for a project.

> >
> >However, there are other problems invoking Ant with the -jar option:
> >1. Ant needs the property ant.home set to the installation directory of
> >Ant.  Since you're using a 1.3 JVM this may not be a requirement but I'm
> >not sure.
> 
> I've never set the ant.home property, nor does it appear that Ant
> sets it internally either.  What does Ant use the ant.home property
> for?  Remember that I'm using the released Ant 1.2, so maybe ant.home
> is new feature.

Since you're using a 1.3 JVM, it might not be necessary.  The reason is,
the "dir" attribute of the <exec> task uses different methods of switching
the current directory before invoking the specified external command.  If
you were using 1.2 or earlier JVM, then Ant would need to find the
bin\antRun.bat file which is done by looking at the value of ant.home.

The ant.home property is part of version 1.2 and has been around since at
least version 1.1 if not earlier.  Look at ant.bat and you'll see it being
defined on the Java command line.

> 
> >2. Ant needs to be able to find the SDK's tools.jar.  This is normally
> >done by setting the JAVA_HOME variable to point to the JDK/SDK directory
> >before running ant.bat.
> 
> I assume that ant needs access to the tools.jar archive for things
> like javac?  Well, my Ant tool isn't using any of the Java tools at
> the moment, so I can probably safely ignore this for the time being.

That's fine.

-Bill Burton

> __________________________________
> James Bucanek
> <ma...@gloaming.com>

Re: Stupid Windows question

Posted by James Bucanek <su...@gloaming.com>.
At 2:01 PM -0500 1/2/01, Bill Burton wrote:
>Hello James,
>
>You could try using what is known as "Download Extensions."  This allows
>one jar file to reference jars elsewhere, normally using a relative
>reference.
>
>Rebuild MyAntTool.jar adding a manifest entry something like this:
>   Class-Path: ant.jar jaxp.jar parser.jar optional.jar
>
>Now, as long as MyAntTool.jar and all these jars listed in the Class-Path
>directive are located in the same directory, MyAntTool.jar will be able to
>find them as necessary.  For more information, see
>http://java.sun.com/docs/books/tutorial/ext/basics/download.html.

This would work if the ant.jar (etc.) jars were together with my 
application, but I really wanted that kind of stuff to be installed 
as common resources on the workstation, independent of my tool or any 
of my projects.  Well, I can see advantages and disadvantages to both 
ways, and this would certainly make some things easier.  Thanks for 
the tip.

>
>However, there are other problems invoking Ant with the -jar option:
>1. Ant needs the property ant.home set to the installation directory of
>Ant.  Since you're using a 1.3 JVM this may not be a requirement but I'm
>not sure.

I've never set the ant.home property, nor does it appear that Ant 
sets it internally either.  What does Ant use the ant.home property 
for?  Remember that I'm using the released Ant 1.2, so maybe ant.home 
is new feature.

>2. Ant needs to be able to find the SDK's tools.jar.  This is normally
>done by setting the JAVA_HOME variable to point to the JDK/SDK directory
>before running ant.bat.

I assume that ant needs access to the tools.jar archive for things 
like javac?  Well, my Ant tool isn't using any of the Java tools at 
the moment, so I can probably safely ignore this for the time being.

__________________________________
James Bucanek
<ma...@gloaming.com>


Re: Stupid Windows question

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

You could try using what is known as "Download Extensions."  This allows
one jar file to reference jars elsewhere, normally using a relative
reference.

Rebuild MyAntTool.jar adding a manifest entry something like this:
  Class-Path: ant.jar jaxp.jar parser.jar optional.jar

Now, as long as MyAntTool.jar and all these jars listed in the Class-Path
directive are located in the same directory, MyAntTool.jar will be able to
find them as necessary.  For more information, see
http://java.sun.com/docs/books/tutorial/ext/basics/download.html.

However, there are other problems invoking Ant with the -jar option:
1. Ant needs the property ant.home set to the installation directory of
Ant.  Since you're using a 1.3 JVM this may not be a requirement but I'm
not sure.
2. Ant needs to be able to find the SDK's tools.jar.  This is normally
done by setting the JAVA_HOME variable to point to the JDK/SDK directory
before running ant.bat.

The following simple batch file sets a few environment variables for
convenience and then calls your GUI.  For instance:
  @echo off
  set JAVA_HOME=D:\jdk1.3
  set ANT_HOME=D:\jakarta-ant
  rem Run GUI which then invokes Ant
  %JAVA_HOME%\bin\java -Dant.home=%ANT_HOME% -cp %JAVA_HOME%\lib\tools.jar
-jar %ANT_HOME%\lib\MyAntTool.jar

The above assumes the appropriate jars in in the Class-Path manifest entry
as described above.  Otherwise, you will have to add them to the -cp
option.

You should also look at the bin\ant.bat script to see how it works.

-Bill Burton

James Bucanek wrote:
> 
> OK, I freely admit that Windows is not my primary platform, nor my
> platform of choice.
> 
> Never the less, I need to get Ant up and running and I'm running into
> a really stupid problem with Java on Windows.
> 
> I have a dedicated machine, that I just installed Win98 and JDK 1.3.
> Nothing else.
> 
> I have written a GUI wrapper around Ant and want to launch it to do
> builds.  But whenever I do, I get a NoClassDefFoundError:
> org/apache/tools/ant/BuildListener.
> 
> So, I assume that Java isn't finding the ant.jar classes.  If I put
> the ant.jar file in the same directory, and specify it on the command
> line (java -cp ant.jar -jar MyAntTool.jar) the program runs just fine.
> 
> But I want to put the ant.jar (and parser.jar, and jaxp.jar, and
> myTasks.jar) somewhere common.  I've read the notes on class paths on
> the java.sun.com site, and have tried (1) setting a CLASSPATH
> environment variable to point to the directory, (2) placing the jars
> in the \jdk1.3\jre\lib\ext, \jdk1.3\jre\lib, and \jdk1.3\lib
> directories, (3) specified those directories in the java command
> options, and (4) combinations of the above (restarting the entire OS
> between configuration changes, of course).
> 
> Nothing works, unless my application and jars are in the same
> directory and I explicitly specify all of the library jar on the
> command line.  Am I missing something?  This can't be that hard!
> 
> P.S. How can you redirect the stderr output from a command to a file?
> 
> Thanks in advance for any insight,
> 
> James
> 
> __________________________________
> James Bucanek
> <ma...@gloaming.com>

RE: Stupid Windows question

Posted by Eric White <ew...@alterna.com>.
this should work

[command] 1> stdout.txt 2> stderr.txt


-----Original Message-----
From: Lars Diestelhorst [mailto:diestelhorst@tuhh.de]
Sent: Tuesday, January 02, 2001 11:12 AM
To: ant-user@jakarta.apache.org
Subject: RE: Stupid Windows question


Hello,

i am not sure, try [command] >> file.txt

Lars Diestelhorst

> -----Original Message-----
> From: James Bucanek [mailto:subscriber@gloaming.com]
> Sent: Tuesday, January 02, 2001 6:55 PM
> To: ant-user@jakarta.apache.org
> Subject: RE: Stupid Windows question
>
>
> At 11:37 AM -0600 1/2/01, Bill Lynch wrote:
> >  > P.S. How can you redirect the stderr output from a command to a file?
> >
> >[command] > file.txt
> >
> >ie:
> >
> >dir > file.txt
> >
> >or
> >ipconfig > file.txt
>
> But this only redirect stdout.  stderr still goes to the shell.
>
> __________________________________
> James Bucanek
> <ma...@gloaming.com>
>


RE: Stupid Windows question

Posted by Lars Diestelhorst <di...@tuhh.de>.
Hello,

i am not sure, try [command] >> file.txt

Lars Diestelhorst

> -----Original Message-----
> From: James Bucanek [mailto:subscriber@gloaming.com]
> Sent: Tuesday, January 02, 2001 6:55 PM
> To: ant-user@jakarta.apache.org
> Subject: RE: Stupid Windows question
>
>
> At 11:37 AM -0600 1/2/01, Bill Lynch wrote:
> >  > P.S. How can you redirect the stderr output from a command to a file?
> >
> >[command] > file.txt
> >
> >ie:
> >
> >dir > file.txt
> >
> >or
> >ipconfig > file.txt
>
> But this only redirect stdout.  stderr still goes to the shell.
>
> __________________________________
> James Bucanek
> <ma...@gloaming.com>
>


RE: Stupid Windows question

Posted by James Bucanek <su...@gloaming.com>.
At 11:37 AM -0600 1/2/01, Bill Lynch wrote:
>  > P.S. How can you redirect the stderr output from a command to a file?
>
>[command] > file.txt
>
>ie:
>
>dir > file.txt
>
>or
>ipconfig > file.txt

But this only redirect stdout.  stderr still goes to the shell.

__________________________________
James Bucanek
<ma...@gloaming.com>


RE: Stupid Windows question

Posted by Bill Lynch <bl...@4charity.com>.
> P.S. How can you redirect the stderr output from a command to a file?

[command] > file.txt

ie:

dir > file.txt

or
ipconfig > file.txt

--Bill

-------------------------------------------------------
4charity.com                        blynch@4charity.com
CoolServlets.com                  bill@coolservlets.com 

> 
> Thanks in advance for any insight,
> 
> James
> 
> __________________________________
> James Bucanek
> <ma...@gloaming.com>
> 
> 

Stupid Windows question

Posted by James Bucanek <su...@gloaming.com>.
OK, I freely admit that Windows is not my primary platform, nor my 
platform of choice.

Never the less, I need to get Ant up and running and I'm running into 
a really stupid problem with Java on Windows.

I have a dedicated machine, that I just installed Win98 and JDK 1.3. 
Nothing else.

I have written a GUI wrapper around Ant and want to launch it to do 
builds.  But whenever I do, I get a NoClassDefFoundError: 
org/apache/tools/ant/BuildListener.

So, I assume that Java isn't finding the ant.jar classes.  If I put 
the ant.jar file in the same directory, and specify it on the command 
line (java -cp ant.jar -jar MyAntTool.jar) the program runs just fine.

But I want to put the ant.jar (and parser.jar, and jaxp.jar, and 
myTasks.jar) somewhere common.  I've read the notes on class paths on 
the java.sun.com site, and have tried (1) setting a CLASSPATH 
environment variable to point to the directory, (2) placing the jars 
in the \jdk1.3\jre\lib\ext, \jdk1.3\jre\lib, and \jdk1.3\lib 
directories, (3) specified those directories in the java command 
options, and (4) combinations of the above (restarting the entire OS 
between configuration changes, of course).

Nothing works, unless my application and jars are in the same 
directory and I explicitly specify all of the library jar on the 
command line.  Am I missing something?  This can't be that hard!

P.S. How can you redirect the stderr output from a command to a file?

Thanks in advance for any insight,

James

__________________________________
James Bucanek
<ma...@gloaming.com>