aspose file tools*
The moose likes Tomcat and the fly likes How to embed tomcat 7 into java application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "How to embed tomcat 7 into java application" Watch "How to embed tomcat 7 into java application" New topic
Author

How to embed tomcat 7 into java application

Rushikesh Pisal
Greenhorn

Joined: Mar 28, 2011
Posts: 7
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

Joined: Jun 25, 2001
Posts: 16228
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Rushikesh Pisal
Greenhorn

Joined: Mar 28, 2011
Posts: 7
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
Marshal

Joined: Mar 22, 2005
Posts: 42596
    
  65
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.


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to embed tomcat 7 into java application