Pergunta

I am trying to configure a Jetty (6.x) WebAppContext with a custom subclass of WebAppClassLoader. In code (Scala), it's simply this:

  val context = new WebAppContext()
  val cwacl = new CustomWebAppClassLoader(context)
  context.setClassLoader(cwacl)
  ...

This works fine when embedding Jetty. In production, however, I just deploy a war file to a stand-alone jetty instance, so there's no opportunity to configure things in code like this.

I can't figure out how to do the same thing via Jetty's configuration files. Any help is appreciated.

Bonus: How would you configure maven-jetty-plugin to use the CustomWebAppClassLoader :)

Foi útil?

Solução

You could use the context config files. There are examples in the contexts/ directory.

This would be something along these lines:

<Configure id="mycontext1" class="org.mortbay.jetty.webapp.WebAppContext">
    <Set name="classLoader">
        <New class="f.q.n.CustomWebAppClassLoader">
           <Arg><Ref id="mycontext1"/></Arg></New>
    </Set>
</Configure>

(See the Jetty XML Syntax configuration reference for more details.)

Outras dicas

As an alternative to using a context config file, you can set the classloader attributes in the pom.xml file, for jetty >= 8.x e.g. not scanning any class within WEB-INF for faster startup:

<plugins>
  <plugin>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>${jetty.version}</version>
    <configuration>
      <webApp>
        <webInfIncludeJarPattern>^$</webInfIncludeJarPattern>
      </webApp>
      <stopKey>foo</stopKey>
      <stopPort>9999</stopPort>
    </configuration>
  </plugin>
</plugins>

Reference: Jetty plugin webapp configuration

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top