• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to embed tomcat 7 into java application

 
Rushikesh Pisal
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to embed Tomcat 7 into application using java program.
Can any buddy provide me steps to do it?

Regards,
Rushikesh
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17993
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The exact instructions are part of the Tomcat documentation. The point of interface is a JavaBean that you construct, initialize, and command to start/stop.
 
Rushikesh Pisal
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can i get java code to embed tomcat 7 into application also deploy and undeploy of war file into that application.
Source code of embedded Tomcat 5 is available on net. but i want for tomcat7.

I have tried it by using following code but it is not working

/*
* it start the embedded tomcat
* Create instance of Embedded class
* it set run mode as run
* it set log handler
* create engine of server
* create the connector
* if ssl is enabled then
* set the keystore, keystore password,
* scheme as https, ssl enabled as true and ciphers to connector *
* and then start the embedded tomcat in SSL environment
*/
//public static void main(String[] argw)
private void startTomcat() throws GenException {
String MethodName = "startTomcat";
String Msg = "";

Engine engine = null;

startTomcatLog();

embedded = new Tomcat();
embedded.setBaseDir(tomcatHome + "/webapps");
embedded.setPort(port);
engine = embedded.getEngine();
engine.setDefaultHost("localhost");

//_context = embedded.addContext(contextPath, tomcatHome + "/webapps");

/*embedded.getHost().setAppBase(tomcatHome + "/webapps");
embedded.getHost().setAutoDeploy(true);
embedded.getHost().setDeployOnStartup(true);
((StandardHost)embedded.getHost()).setUnpackWARs(true);

host = embedded.getHost();*/



host = new org.apache.catalina.core.StandardHost();
host.setAppBase(tomcatHome + "/webapps");
host.setAutoDeploy(true);
host.setDeployOnStartup(true);
((StandardHost)host).setUnpackWARs(true);


_context = new StandardContext();
_context.setPath(contextPath);

host.addChild(_context);
engine.addChild(host);
try {
if(sslEnabled)
{
addConnector(port, true);
} else {
addConnector(port, false);
}
} catch (IOException IOE) {
Msg = "Cannot create connector for embedded tomcat server." + ACESystem.NewLine + getStack(IOE);
TransactionUtilities.addLogAndTrace(IOE, ModuleName, MethodName, Msg);
GenException ge = new GenException(ERROR_CAN_NOT_START_TOMCAT, IOE, Msg);
throw ge;
} catch (Exception E) {
Msg = "Got exception while creating connector for embedded tomcat server." + ACESystem.NewLine + getStack(E);
TransactionUtilities.addLogAndTrace(E, ModuleName, MethodName, Msg);
GenException ge = new GenException(ERROR_CAN_NOT_START_TOMCAT, E, Msg);
throw ge;
}

try {
embedded.start();
System.out.println("Started..");
} catch (LifecycleException SE) {
Msg = "Got LifecycleException while starting embedded tomcat server." + ACESystem.NewLine + getStack(SE);
TransactionUtilities.addLogAndTrace(SE, ModuleName, MethodName, Msg);
GenException ge = new GenException(ERROR_CAN_NOT_START_TOMCAT, SE, Msg);
throw ge;
} catch (Exception E) {
Msg = "Got LifecycleException while starting embedded tomcat server." + ACESystem.NewLine + getStack(E);
TransactionUtilities.addLogAndTrace(E, ModuleName, MethodName, Msg);
GenException ge = new GenException(ERROR_CAN_NOT_START_TOMCAT, E, Msg);
throw ge;
}

embedded.getServer().await();
}
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By searching for tomcat 7 embedded I get numerous promising results; did none of those work for you? Which ones did you try?

Also please note that ItDoesntWorkIsUseless.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic