aspose file tools*
The moose likes Tomcat and the fly likes How to stop and start existing application in tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "How to stop and start existing application in tomcat" Watch "How to stop and start existing application in tomcat" New topic
Author

How to stop and start existing application in tomcat

Robert Jack
Ranch Hand

Joined: Apr 13, 2010
Posts: 39
Hi,

I developed simple application "myproject" and deployed in tomcat-6.0.29.

Application stopped when i execute this "http://localhost:8080/manager/stop?path=/myproject".

Is possible to stop this application using java program?

Is possible to start this application using java program?

Help me.
Thanks in advane
Eswar Nec
Ranch Hand

Joined: May 02, 2010
Posts: 105
Hi jack,

Try this

Process p = r.exec("wget http://tomcatusername:tomcatepassword@localhost:8080/manager/" + action + "?path=/myproject -O - -q");



Wake up! Don't let your smile be snatched away by anybody!
Regards, Eswar
Robert Jack
Ranch Hand

Joined: Apr 13, 2010
Posts: 39
Hi eswar. Thanks for your support.

I check your code. It works fine in Linux Ubuntu. Windows not support
I got error when execute in windows

Error is:



Anyone help me.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15665
    
  15

One of the reasons why Linux is so much better for software development than Windows is that Linux comes with an immense number of developer utility programs. Windows does not.

You have 2 choices.

1. You can download and install Cygwin, which allows you to run Linux programs under Windows

2. You can google around and find and install a Windows native "wget" program from some third party.

For a single need, I recommend answer #2, since Cywin is practically an OS in its own right, but either solution will work.


Customer surveys are for companies who didn't pay proper attention to begin with.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12683
    
    5
Whats wrong with using java.net.HttpURLConnection and the rest of the standard library to do a GET request and read the response?

Why would you need to create a Process?

Bill

Java Resources at www.wbrogden.com
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15665
    
  15

Actually, now that I look at the original question, yes, there are several ways in Java to start/stop apps in Java code.

I believe JSR-77 specifies one of them. JMX provides another, I think. Neither requires the existence of an external program such as wget.
Robert Jack
Ranch Hand

Joined: Apr 13, 2010
Posts: 39
Tim Holloway wrote:Actually, now that I look at the original question, yes, there are several ways in Java to start/stop apps in Java code.

I believe JSR-77 specifies one of them. JMX provides another, I think. Neither requires the existence of an external program such as wget.


Hi Tim Holloway,
Thanks for your response.
But i can't get your idea.

Can you give me some more idea about your answer or reference,
regarding start/stop an existing application in tomcat using java code.


Help me.
Thanks in advance.
Robert Jack
Ranch Hand

Joined: Apr 13, 2010
Posts: 39
William Brogden wrote:Whats wrong with using java.net.HttpURLConnection and the rest of the standard library to do a GET request and read the response?

Why would you need to create a Process?

Bill


Hi William Brogden, Thanks for your effort
I got exception when i use HttpURLConnection. I don't know, where i made mistake?
Error is
IOException: java.io.IOException: Server returned HTTP response code: 401 for URL: http://localhost:8080/manager/html/stop?path=/myproject
My code is:




Help me.
Thanks in advance
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12683
    
    5
401 = UNAUTHORIZED - the management app is protected, you need a user in the "managememt" role in order to run the manager app.

Bill
Robert Jack
Ranch Hand

Joined: Apr 13, 2010
Posts: 39
William Brogden wrote:401 = UNAUTHORIZED - the management app is protected, you need a user in the "managememt" role in order to run the manager app.

Bill

Thanks for your support.

How i configure the 'user' in the management role in order to run the manage application?

Help me
Thanks in advance.
Robert Jack
Ranch Hand

Joined: Apr 13, 2010
Posts: 39
I check My tomcat-user.xml file. But its not working

I need to add any role in my tomcat-user.xml file.

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15665
    
  15

There should be model role definitions in the originally-supplied tomcat-users.xml file that will suffice. Although as shipped they may be commented out.

When a server returns a 401 response, the client must log in. That means that a request containing the encoded userid and password must be sent to Tomcat to be validated. Once your client app has logged in, then you can send Tomcat admin URLs.

And, no, I don't have any code like that lying around. I'd have to do the same thing I recommend that you do: Google. Useful magic words include "RFC" and "Basic Authentication", since the definitive documentation for handling a 401 (Basic Authentication) request is one of the Internet RFC documents, which will typically include simple examples of how things are done. If your client app hasn't disabled cookies, a successful login request will return a cookie which will be used to maintain the session context for future requests. And, if you're using the HttpURLConnection, cookie handling is completely automatic, so you don't need to code anything for it.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12683
    
    5
Note that you have to restart Tomcat if you change the users xml file.

Test by using the html interface with a browser - http://yoursite/manager/html/list - you should get a security dialog to enter name and password.

If that works then http://username:userpw@yoursite/manager.... etc should work as the url to GET

Bill
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15665
    
  15

William Brogden wrote:Note that you have to restart Tomcat if you change the users xml file.


That was true with the original MemoryRealm. I think its newer derivatives are smarter about that. Can't hurt, though.


If that works then http://username:userpw@yoursite/manager.... etc should work as the url to GET


Or better, use the https protocol. The http protocol is vulnerable to wire sniffing. Even if only intranet clients control Tomcat this way. it's good practice.
Robert Jack
Ranch Hand

Joined: Apr 13, 2010
Posts: 39
Not working.
My "tomcat-users.xml" file content

I deploy my web application in my local system. application name is "jsfproject"
Then my java code like this

Eventhough i got message "Method failed: HTTP/1.1 401 Unauthorized". I don't know whats wrong my code


Step 1 : I create simple JSF project. and deployed in tomcat. project name "jsfproject"

Step 2 : I create another one JSF application "Demo Project"

Stpe 3 : This "Demo Project" have only one "test.jsp" page. I create only one button "Stop JSF project" in that test.jsp page

Stpe 4 :

Step 5 :

I got the following message when i click "stop JSF project" button

Going to stop the application......
Method failed: HTTP/1.1 401 Unauthorized



Help me,
Thanks for valuable effort


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to stop and start existing application in tomcat
 
Similar Threads
How to run GWT applications on tomcat or any other server.
Greetings!
How to stop maven-package generate metamodel classes?
Give the easiest example which differentiate "interface" and "abstract class" in Java.
Fetch 10K rows from table