Looking at the following example of an embedded Jetty Example: http://musingsofaprogrammingaddict.blogspot.com.au/2009/12/running-jsf-2-on-embedded-jetty.html
The following code sample is given (below.
The author then goes on an gives an example of referring to context params in a web.xml file. eg
...
<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>com.sun.el.ExpressionFactoryImpl</param-value>
</context-param>
...
My question is - if I want to do everything in a Java class - is there a way to set context-params programmatically?
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();
}
}
<init-param> defines a value available to a single specific servlet within a context. <context-param> defines a value available to all the servlets within a context.
With context file for the webapp, they probably mean the jetty. xml configuration file, which can also be used on a per-app basis, when you name it jetty-web. xml and place it in your WEB-INF directory (alongside the web. xml configuration file).
The “context-param” tag is define in “web. xml” file and it provides parameters to the entire web application. For example, store administrator's email address in “context-param” parameter to send errors notification from our web application.
We can now send a request to the /heavy/async endpoint – that request will be handled by the Jetty in an asynchronous way: String url = "http://localhost:8090/heavy/async"; HttpClient client = HttpClientBuilder. create(). build(); HttpGet request = new HttpGet(url); HttpResponse response = client.
In your case
wac.setInitParameter("com.sun.faces.expressionFactory",
"com.sun.el.ExpressionFactoryImpl")
will do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With