I want to start tomcat server programmatically in JAVA. Please help me
Asked
Active
Viewed 3,475 times
0
-
Look for invoking a new JVM from Java or for starting catalina in a new thread, depending on what you want to do. – AlexR Jul 24 '14 at 08:51
-
Use java Runtime to execute the batch file. Probably run.bat. – Syam S Jul 24 '14 at 08:52
-
http://blog.faultylabs.com/2011.php?t=ant – Konstantin V. Salikhov Jul 24 '14 at 08:55
-
3possible duplicate of [How to start and stop tomcat using java code?](http://stackoverflow.com/questions/5256002/how-to-start-and-stop-tomcat-using-java-code) – tomdavies Jul 24 '14 at 08:57
2 Answers
3
If I understood you well, you are interested in running tomcat on your event from application. If it is the case, you can write your own method to run tomcat.
This is example:
public void stopRunTomcat(){
try{
Socket s = new Socket(server,8005);
if(s.isConnected()){
PrintWriter print = new PrintWriter(s.getOutputStream(),true);
//Stop tomcat if it is already started
print.println("SHUTDOWN");
print.close();
s.close();
}
//Run tomcat
Runtime.getRuntime().exec(System.getProperty("catalina.home")+"\\bin\\startup.sh");
}catch (Exception ex){
ex.printStackTrace();
}
}
You have to adopt this code to your paths and OS. After that you can call this method from event which have to raise tomcat.
I hope that helps.

Bosko Mijin
- 3,287
- 3
- 32
- 45
0
If you use maven give a look to it's cargo plugin: http://cargo.codehaus.org/Tomcat+7.x I'm sure other build/dependency management tools have something similar as well. (http://cargo.codehaus.org/Functional+testing) Regards, Tamás

uthomas
- 677
- 2
- 9
- 17