marc2112 wrote:
> Hi,
>
> I'm trying to embed Jetty in my own process. I created a jar file that
> has all of my webapp resources under a directory in the jar called
> webapp (/webapp). I want the context root to my webapplication to just
> be "/". This is how it works when I run from Eclipse (so no jar file,
> everything in eclipse's classloader). When I run from the jar, the
> context root is /webapp (the name of the directory).
>
> Any thoughts on what I might be doing wrong?
>
> My code is pasted below.
>
> Thanks,
> ---Marc
>
> public class ReverseProxy implements Runnable, InitializingBean {
> private static final Logger log = Logger.getLogger(
> ReverseProxy.class );
>
> @Autowired
> private Config config;
>
> @Autowired
> private Server jetty;
>
> /**
> * This is just a directory within your source tree, and
> * can be exported as part of your normal .jar
> */
> private String webappDir = "webapp";
>
> private String contextPath = "/";
>
> private String resourceBase = webappDir;
> private boolean resourceBaseWasChanged = false;
>
> /**
> * This is the name of the class to use to load the webapp directory
> */
> private String classNameForResourceLoading = getClass().getName();
>
> private boolean enableJmx = true;
>
> @Override
> public void run() {
> Server jettyServer = getJetty();
>
> if ( enableJmx ) {
> // -- add jmx
> MBeanServer platformMBeanServer =
> ManagementFactory.getPlatformMBeanServer();
> MBeanContainer jmxContainer = new
> MBeanContainer(platformMBeanServer);
>
> jettyServer.getContainer().addEventListener(jmxContainer);
> jettyServer.addBean(jmxContainer); //Add to the
> Server as a lifecycle
> jmxContainer.addBean( Log.getLog() );
> }
>
> // -- add webapp files from jar
> Class loaderClass;
> try {
> loaderClass = Class.forName(
> getClassNameForResourceLoading() );
> } catch (ClassNotFoundException e) {
> log.fatal( "Unable to load class " +
> getClassNameForResourceLoading(), e );
> return;
> }
> final URL warUrl =
> loaderClass.getClassLoader().getResource( webappDir );
>
> if ( warUrl == null ) {
> log.fatal( "Unable to load resource " + webappDir );
> return;
> }
>
> final String warUrlString = warUrl.toExternalForm();
> WebAppContext webAppContext = new WebAppContext( );
> webAppContext.setWar( warUrlString );
> webAppContext.setContextPath( contextPath );
> // webAppContext.setResourceBase( resourceBase );
> webAppContext.setLogUrlOnStart(true);
> jettyServer.setHandler( webAppContext );
> webAppContext.setClassLoader( getClass().getClassLoader() );
>
>
> // -- set default web.xml (register JSP handler, etc)
> String defaultWebXml = webappDir + "/WEB-INF/webdefault.xml";
> webAppContext.setDefaultsDescriptor(defaultWebXml);
>
> HashMap<String, String> ctxInitParams = new
> HashMap<String, String>();
>
> ctxInitParams.put("org.eclipse.jetty.servlet.SessionDomain",
> config.getProperty("portal.cookieDomain", "
gcotdwx0178.nam.nsroot.net