Skip to content

Instantly share code, notes, and snippets.

@claymccoy
Created December 18, 2009 20:22
Show Gist options
  • Save claymccoy/259737 to your computer and use it in GitHub Desktop.
Save claymccoy/259737 to your computer and use it in GitHub Desktop.
// OS X 10.6.2, Java 1.6.0_17, tomcat 6.0.18
// Trying to setup embedded tomcat. Initialization goes well according to the log.
// The Spring config runs, and everythign starts up. No errors.
// But I get 404s when browsing to the site. It's as if it can't find my jsp's.
// it is a Maven project with a Maven file structure, <approot> is a placeholder that is not in the actual code
webAppPath = new File("<approot>/WEB/src/main/webapp"); // parent location of WEB-INF/web.xml
warPath = new File("<approot>/WEB/target"); // parent location of the war
port = port;
path = "/App";
// using the above values to start the server
// create server
final Embedded embedded = new Embedded();
embedded.setCatalinaHome(catalinaHome);
// create engine
final Engine engine = embedded.createEngine();
engine.setName("localEngine");
// create host
final Host localHost = embedded.createHost("localHost", warPath.getAbsolutePath());
engine.addChild(localHost);
engine.setDefaultHost(localHost.getName());
// create context
final Context rootContext = embedded.createContext(path, webAppPath.getAbsolutePath());
rootContext.setParentClassLoader(Thread.currentThread().getContextClassLoader());
localHost.addChild(rootContext);
embedded.addEngine(engine);
// create http connector
final Connector httpConnector = embedded.createConnector((InetAddress) null, port, false);
embedded.addConnector(httpConnector);
// start server
embedded.start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment