| Author |
Starting Tomcat from ANT
|
Rich Smyth
Ranch Hand
Joined: May 30, 2002
Posts: 87
|
|
Before I run my build from within the eclipse IDE I have to make sure Tomcat is not running. Is there any way for an ANT target to run a batch file to stop Tomcat, wait 3 seconds, then carry on with the rest of my build? I had no success with <exec dir="${tomcat.home}/bin" executable="startup.bat"/> Rich
|
 |
Rich Smyth
Ranch Hand
Joined: May 30, 2002
Posts: 87
|
|
I should add that the build produces the following error. The reference to line 78 of build.xml is the <exec> task shown in the previous post. Build exception: file:C:/Projects/EMIT/WEB-INF/config/build.xml:78: Execute failed: java.io.IOException: CreateProcess: startup.bat error=2 Build exception: file:C:/Projects/EMIT/WEB-INF/config/build.xml:78: Execute failed: java.io.IOException: CreateProcess: startup.bat error=2 file:C:/Projects/EMIT/WEB-INF/config/build.xml:78: Execute failed: java.io.IOException: CreateProcess: startup.bat error=2 at org.apache.tools.ant.taskdefs.ExecTask.runExec(ExecTask.java:371) at org.apache.tools.ant.taskdefs.ExecTask.execute(ExecTask.java:250) at org.apache.tools.ant.Task.perform(Task.java:319) at org.apache.tools.ant.Target.execute(Target.java:309) at org.apache.tools.ant.Target.performTasks(Target.java:336) at org.apache.tools.ant.Project.executeTarget(Project.java:1306) at org.apache.tools.ant.Project.executeTargets(Project.java:1250) at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:262) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.eclipse.ant.core.AntRunner.run(AntRunner.java:234) at org.eclipse.ui.externaltools.internal.core.AntFileRunner.execute(AntFileRunner.java:56) at org.eclipse.ui.externaltools.internal.core.DefaultRunnerContext.executeRunner(DefaultRunnerContext.java:428) at org.eclipse.ui.externaltools.internal.core.DefaultRunnerContext.run(DefaultRunnerContext.java:479) at org.eclipse.ui.externaltools.internal.ui.AntLaunchWizard$1.run(AntLaunchWizard.java:117) at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:98) Caused by: java.io.IOException: CreateProcess: startup.bat error=2 at java.lang.Win32Process.create(Native Method) at java.lang.Win32Process.<init>(Win32Process.java:63) at java.lang.Runtime.execInternal(Native Method) at java.lang.Runtime.exec(Runtime.java:566) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.apache.tools.ant.taskdefs.Execute$Java13CommandLauncher.exec(Execute.java:647) at org.apache.tools.ant.taskdefs.Execute.launch(Execute.java:417) at org.apache.tools.ant.taskdefs.Execute.execute(Execute.java:428) at org.apache.tools.ant.taskdefs.ExecTask.runExecute(ExecTask.java:329) at org.apache.tools.ant.taskdefs.ExecTask.runExec(ExecTask.java:368) ... 17 more --- Nested Exception --- java.io.IOException: CreateProcess: startup.bat error=2 at java.lang.Win32Process.create(Native Method) at java.lang.Win32Process.<init>(Win32Process.java:63) at java.lang.Runtime.execInternal(Native Method) at java.lang.Runtime.exec(Runtime.java:566) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.apache.tools.ant.taskdefs.Execute$Java13CommandLauncher.exec(Execute.java:647) at org.apache.tools.ant.taskdefs.Execute.launch(Execute.java:417) at org.apache.tools.ant.taskdefs.Execute.execute(Execute.java:428) at org.apache.tools.ant.taskdefs.ExecTask.runExecute(ExecTask.java:329) at org.apache.tools.ant.taskdefs.ExecTask.runExec(ExecTask.java:368) at org.apache.tools.ant.taskdefs.ExecTask.execute(ExecTask.java:250) at org.apache.tools.ant.Task.perform(Task.java:319) at org.apache.tools.ant.Target.execute(Target.java:309) at org.apache.tools.ant.Target.performTasks(Target.java:336) at org.apache.tools.ant.Project.executeTarget(Project.java:1306) at org.apache.tools.ant.Project.executeTargets(Project.java:1250) at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:262) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.eclipse.ant.core.AntRunner.run(AntRunner.java:234) at org.eclipse.ui.externaltools.internal.core.AntFileRunner.execute(AntFileRunner.java:56) at org.eclipse.ui.externaltools.internal.core.DefaultRunnerContext.executeRunner(DefaultRunnerContext.java:428) at org.eclipse.ui.externaltools.internal.core.DefaultRunnerContext.run(DefaultRunnerContext.java:479) at org.eclipse.ui.externaltools.internal.ui.AntLaunchWizard$1.run(AntLaunchWizard.java:117) at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:98) Build exception: file:C:/Projects/EMIT/WEB-INF/config/build.xml:78: Execute failed: java.io.IOException: CreateProcess: startup.bat error=2
|
 |
Amol Desai
Ranch Hand
Joined: Jan 29, 2003
Posts: 82
|
|
Hi , Start tomcat by using the following <target name="start" > <exec executable="${tomcat.home}/bin/startup.bat" os="Windows 2000" /> </target> It should work. To stop the server <target name=stop"> <exec executable="${tomcat.home}/bin/shutdown.bat" os="Windows 2000" /> </target> To confirm whether tomcat is running or not in your build process, use as below <target name="start" depends ="stop" /> This will stop the tomcat server and then start it again. Note that you can continue with the build(it won't fail) even if the server is not running.
|
 |
Rich Smyth
Ranch Hand
Joined: May 30, 2002
Posts: 87
|
|
Thanks for the tip. I now have ANT targets that stop and start Tomcat. My problem now is that once Tomcat starts up, the rest of my build hangs? Do I need and extra step somewhere to get past the tomcatGo target? <target name = "tomcatGo"> <exec dir="${tomcat.home}/bin" executable="${tomcat.home}/bin/startup.bat" os="Windows XP" /> <sleep seconds="10" /> </target> Rich
|
 |
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
|
|
(Fully realizing that this is an old conversation, but always glad to keep the information on the forums up to date for folks that search through them for information...) According to the exec task documentation, Ant 1.6 added a new attribute to the task - the spawn attribute. If you set it to true, then the exec task spawns a separate process to run the specified executable, and the ant script continues. I've not figured out a similar solution for pre-1.6 Ant.
|
[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
|
 |
Sandeep Agar
Greenhorn
Joined: May 19, 2006
Posts: 1
|
|
Did you have any luck with this issue? Thanks, Sandeep
|
 |
Nick Potter
Ranch Hand
Joined: May 07, 2008
Posts: 125
|
|
Hi,
Did anyone find a workaround for this? Even with spawn="true", ant doesn't open .bat files. 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.
|
 |
Martijn Verburg
author
Bartender
Joined: Jun 24, 2003
Posts: 3268
|
|
Hi Nick,
We try not to wake the zombies (old threads) around here. Can you please post your specific question as a separate topic, thanks!
|
Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
|
 |
 |
|
|
subject: Starting Tomcat from ANT
|
|
|