File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Ant, Maven and Other Build Tools and the fly likes Opening .bat files from ant Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Opening .bat files from ant" Watch "Opening .bat files from ant" New topic
Author

Opening .bat files from ant

Nick Potter
Ranch Hand

Joined: May 07, 2008
Posts: 126
Hi,

Did anyone manage to open .bat files from ant? I'm trying to open the tomcat console through ant tasks.
I'm doing this:


I also tried this with no success:



The error is:

start-tomcat:
[exec] The CATALINA_HOME environment variable is not defined correctly
[exec] This environment variable is needed to run this program

This is a little strange though since TOMCAT_HOME is defined correctly (i also set another env var CATALINA_HOME, no luck).
I have no problem opening tomcat6.exe though, even if it doesn't show the window, but the process is there when i open windows task manager.

Can anyone help? Thanks.

Edit: i'm using jdk 1.6, tomcat 6 and ant 1.7 from eclipse ganymede, but it doesn't work when i run the task outside of eclipse either.
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Where are you defining CATALINA_HOME?


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Nick Potter
Ranch Hand

Joined: May 07, 2008
Posts: 126
in environment variables.
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

OK,

That's one theory down, next thing: Can you echo the values of the various environment variables before the start.bat is called?
Nick Potter
Ranch Hand

Joined: May 07, 2008
Posts: 126
Yes, also deploying the application works just fine... no problems till i want to start the tomcat console. I read somewhere that there's a problem opening the .bat files with latest versions of ant. On another machine i have tomcat 4 and ant 1.0 (i think) and i have no problem.
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Hmm, not sure in that case, I did find an alternative for you here
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16158
    
  21

Just for a slightly different angle of attack: Tomcat is a Java program. That means that Ant can bypass the whole script-thingy stuff and launch it directly.

In fact, since Tomcat is embeddable, you could even create an Ant task to do the whole thing - probably someone's already done so.

Customer surveys are for companies who didn't pay proper attention to begin with.
Nick Potter
Ranch Hand

Joined: May 07, 2008
Posts: 126
With <exec executable="{tomcat.home}/bin/startup.bat" spawn="true"> it doesn't open it.
With <exec executable="{tomcat.home}/bin/tomcat6.exe" spawn="true"> it works.

I want it to open the tomcat console, but it doesn't. With tomcat 4, jdk 1.4, ant 1.0 this works : <exec executable="{tomcat.home}/bin/startup.bat" spawn="true">
With tomcat6, jdk1.6, 1.7 it doesn't.
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Hi Nick,

I know this is a bit of a hassle, but are you able to drop the Ant version to 1.6 and try that? I'm curious to see if it's the exec task of 1.7 that's mucking things up (I've googled and couldn't find anything however).
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16158
    
  21

I'm not sure what "Tomcat console" means here. The tomcat admin webapps aren't part of the base tomcat download anymore - they have to be downloaded separately. But they wouldn't open automatically, since they're webapps and therefore only respond to web requests.

If you mean a DOS-style command window, you'd have to open a new command window and have IT run tomcat. I forget the details.

One possible reason why this happened automatically before and doesn't now might be that the older version was dumping output to stdout and that forced a console window to open to display it. Not all Tomcat configurations write to stdout. Tomcat itself doesn't, and well-written webapps don't either, since there's no universal rule on where System.out/err.print's will go (if anywhere). That's why logging is preferable. In Tomcat, system.out prints generally go to logs/catalina.out, though I forget if a localhost or app-specific log might get them instead.
Nick Potter
Ranch Hand

Joined: May 07, 2008
Posts: 126
By tomcat console i mean the dos-style command window. I also tried to open the command window (cmd.exe) and have it run tomcat . I'm using stdout in log4j configuration to have it print my sysout's in tomcat console. I'll have to trt using ant 1.6 just to see if this is an ant version problem.
Nick Potter
Ranch Hand

Joined: May 07, 2008
Posts: 126
Ok, i managed to get it done.
Strange enough (to me at least) this piece of code doesn't work although i set the tomcat.home variable correctly in the build.properties file:


But this one does work:


Maybe someone's got an explanation?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Opening .bat files from ant