Start Tomcat via ant without blocking

On separate question (Q_26960200.html I asked about how to stop and start Tomcat using ANT.
The original solution works great for stopping Tomcat.
However, when starting the Tomcat, Ant waits for the tomcat service to end before allowing any new builds.

I tried using both the jar method, and method which CEHJ suggested, in calling startup.bat, but both methods cause  ANT to block further builds until the Tomcat service is halted.

LVL 30
AxterAsked:
Who is Participating?
 
CEHJCommented:
>>However, when starting the Tomcat, Ant waits for the tomcat service to end

What are you attempting to do - to allow another instance of Tomcat to start while a service is still running?
0
 
AxterAuthor Commented:
>>What are you attempting to do - to allow another instance of Tomcat to start while a service is still running?

I just want to always be able to select the ant build option, to stop tomcat, before uploading new war file, and then restart tomcat.

IE:
1. Stop tomcat
2. Remove old war file under tomcat\webapps
3. Remove old dir associated with war file under tomcat\webapps
4. Build new war file
5. Copy new war file to tomcat\webapps
6. Startup tomcat

If build hangs (gets blocked) when calling step 6, that means I have to manually stop tomcat, before I can run the build again.
I'm trying to set it up so all steps are automated.

0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
AxterAuthor Commented:
I should mention, that this is part of a larger plan to include test automation, in which I want the automated test to occur on a completely clean environment.
At least clean for Tomcat.
0
 
AxterAuthor Commented:
I got a some what working method.
I create bat file startupnonblocking.bat under tomcat\bin with the following:
cmd /c C:\tomcat\bin\startup.bat

This method works pretty good, but I would like to be able to call above command directly from ant.
When I tried I got the following error:
E:\Tip\WebCrawler\ant\build.xml:100: Execute failed: java.io.IOException: Cannot run program "cmd" (in directory "E:\Tip\WebCrawler\ant"): CreateProcess error=740, The requested operation requires elevation

Below is what I have in ant.
...
	<target name="tomcat-start-via-script">
		<echo>Starting Tomcat via script</echo>
	     <exec executable="cmd">
	        <arg line="/c"/>
    		<arg line="'${tomcat.home}\bin\startup.bat'"/>
	     </exec>
	</target>

Open in new window

0
 
CEHJCommented:


>>cmd /c C:\tomcat\bin\startup.bat

Try instead
REM Start Tomcat in batch file
call C:\tomcat\bin\startup.bat

Open in new window

0
 
AxterAuthor Commented:
>>Try instead

That's the first thing I tried, and it doesn't work from ant.  Ant still blocks.
It works on the command line, but I'm not sure why when called from ant, it blocks.
0
 
CEHJCommented:
(That would be a batch file, called directly in the exec task). You might need to throw a runas into the mix if privileges are not high enough
0
 
AxterAuthor Commented:
>>(That would be a batch file, called directly in the exec task). You might need to throw a runas into the mix if privileges are not high enough
I'm trying to avoid using runas.

I don't see this error if I call the batch file with the cmd /c command.
So I would think ANT could call this directly, if it can call it via batch.
0
 
CEHJCommented:
You might also try
<target name="tomcat-start-via-script">
		<echo>Starting Tomcat via script</echo>
	     <exec executable="cmd">
	        <arg line="/c"/>
    		<arg line="call ${tomcat.home}\bin\startup.bat"/>
	     </exec>
	</target>

Open in new window

0
 
AxterAuthor Commented:
I got the same error:
BUILD FAILED
E:\Tip\WebCrawler\ant\build.xml:89: Execute failed: java.io.IOException: Cannot run program "cmd" (in directory "E:\Tip\WebCrawler\ant"): CreateProcess error=740, The requested operation requires elevation

It seems ant has a problem calling cmd directly.
0
 
CEHJCommented:
Does it still happen when you have an elevated cmd.exe from which to call the  Ant script?
0
 
AxterAuthor Commented:
>>http://www.techrena.net/windows/fix-requested-operation-requires-elevation-error/

That works!
I started Eclipse with "Run as Administrator", and I no longer see the error.
0
 
AxterAuthor Commented:
Thanks
0
 
CEHJCommented:
:)

Could you possibly post your final version?
0
 
AxterAuthor Commented:
>>Could you possibly post your final version?

Actually, I didn't realize it, but it still blocked with the following:
      <target name="tomcat-start-via-script">
            <echo>Starting Tomcat via script</echo>
           <exec executable="cmd">
              <arg line="/c"/>
                <arg line="${tomcat.home}\bin\startup.bat"/>
           </exec>
      </target>

I now longer see the elevated error, but the call still blocks calling other builds, until tomcat is manually stopped.

For now, I'm going to keep the above ant target for special usage, and use the following as default start up method:
      <target name="tomcat-start-script">
            <echo>Starting Tomcat via Windows Service</echo>
           <exec executable="${tomcat.home}\bin\startupNonBlocking.bat">
           </exec>
      </target>

With startupNonBlocking.bat script having the following:
cd C:\tomcat
cmd /c C:\tomcat\bin\startup.bat

I added the cd, because I notice a side effect of calling just cmd, in that files created by WebApps java code, were created in the tomcat\bin file instead of tomcat base folder.

0
 
CEHJCommented:
http:#35418367 (or something like it) shouldn't block
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.