有没有办法在嵌入式jetty中以编程方式设置context-params?

问题描述:

寻找在一个嵌入式码头实施例的以下示例: http://musingsofaprogrammingaddict.blogspot.com.au/2009/12/running-jsf-2-on-embedded-jetty.html有没有办法在嵌入式jetty中以编程方式设置context-params?

下面的代码示例给出(下面

作者然后继续一个给出参照上下文参数在网络的一个例子。 XML文件,例如

... 
<context-param> 
    <param-name>com.sun.faces.expressionFactory</param-name> 
    <param-value>com.sun.el.ExpressionFactoryImpl</param-value> 
</context-param> 
... 

我的问题是 - 如果我想在一个Java类做的一切 - ?有没有一种方法来设置上下文PARAMS编程

public class JettyRunner { 

    public static void main(String[] args) throws Exception { 

     Server server = new Server(); 

     Connector connector = new SelectChannelConnector(); 
     connector.setPort(8080); 
     connector.setHost("127.0.0.1"); 
     server.addConnector(connector); 

     WebAppContext wac = new AliasEnhancedWebAppContext(); 
     wac.setContextPath("/myapp"); 
     wac.setBaseResource(
      new ResourceCollection(
       new String[] {"./src/main/webapp", "./target"})); 
     wac.setResourceAlias("/WEB-INF/classes/", "/classes/"); 

     server.setHandler(wac); 
     server.setStopAtShutdown(true); 
     server.start(); 
     server.join(); 
    } 
} 

在你的情况

wac.setInitParameter("com.sun.faces.expressionFactory", 
        "com.sun.el.ExpressionFactoryImpl") 

会做。

ServletContextHandler context = new ServletContextHandler(
      ServletContextHandler.SESSIONS); 
    context.setContextPath("/"); 

上面的代码应该为你工作。