I'm going to accept @vanje answer since it got me thinking into right direction. Here's what I ended up using:
- Create jetty-web.xml outside of your WAR distro (no you don't want to package it with WAR if you want to configure the app from "outside")
- Place
jetty-web.xml
alongside of jetty.xml
- I needed just a single parameter so I ended up with the following:
jetty-web.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN"
"http://jetty.mortbay.org/configure.dtd">
<Configure class="org.mortbay.jetty.webapp.WebAppContext">
<New class="org.mortbay.jetty.plus.naming.EnvEntry">
<Arg>myOwnParam</Arg>
<Arg type="java.lang.String">//some/path/to/the/file</Arg>
</New>
</Configure>
Java snippet
InitialContext c = new InitialContext();
EnvEntry env = (EnvEntry)
c.lookup("org.mortbay.jetty.plus.naming.EnvEntry/myOwnParam");
final String myString = (String) env.getObjectToBind();
The biggest gotcha for me here was that I was trying to get myString
from the defaul env which didn't work until I realized that JNDI was using local context. This is OK for me but will break portability if you try to move WAR on say Tomcat. If someone can post an example how this can be saved into default context that would be greatOwnParam