In Jersey 1 it was possible to pass @Context ServletContext servletContext to the constructor of an Application class, but in Jersey 2 this no longer works. It seems Jersey 2 will only inject at request time.
To work around this in Jersey 2, use an anonymous ContainerRequestFilter to gain access to a ServletContext at request time and pass the required init parameters into the Application class.
public class MyApplication extends Application { @Context protected ServletContext servletContext; private String myInitParameter; @Override public Set<Object> getSingletons() { Set<Object> singletons = new HashSet<Object>(); singletons.add(new ContainerRequestFilter() { @Override public void filter(ContainerRequestContext containerRequestContext) throws IOException { synchronized(MyApplication.this) { if(myInitParameter == null) { myInitParameter = servletContext.getInitParameter("myInitParameter"); // do any initialisation based on init params here } } } return singletons; }); }; }