I am writing a web application that runs within an embedded Jetty instance.
When I attempt to execute a JSTL statement, I receive the following exception:
By adding the following code I got rid of the problem:
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>jasper</artifactId>
<version>6.0.29</version>
</dependency>
I am using jetty-runner 8.
I got the same problem on Jetty 7, I solved it by enabling Jetty to search for TLD:
I did it by setting an attribute on the context:
Server server = new Server(80);
WebAppContext context = new WebAppContext("pig-1.0-SNAPSHOT.war","/");
context.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",
".*/.*jsp-api-[^/]*\\.jar$|.*/.*jsp-[^/]*\\.jar$|.*/.*taglibs[^/]*\\.jar$");
server.addHandler(context);
server.start();
Refer to http://wiki.eclipse.org/Jetty/Howto/Configure_JSP#Using_JSTL_Taglibs_for_Jetty_7.x_and_8.x for further details.
On my project (using maven), I have standard TLDs are on the JAR "org.apache.taglibs.standard.glassfish-1.2.0.v2011120803.jar" and theoretically it would be enough to use as value for ContainerIncludeJarPattern the following pattern:
".*/org\\.apache\\.taglibs\\.standard\\.glassfish-1\\.2\\.0\\.v201112081803\\.jar"
It actually works and it is a confirmation of where do jetty found the tag libs, but I've preferred to leave the previous pattern which I found on the wiki.eclipse.org page linked above.
It may be required to extend the pattern if you want to include custom tag libs.
The jstl taglibs must be on server classpath. You can add a classloader to current classloader chain before start the server. That's the principle used by start.jar when it start a jetty server.
ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
URL urlTaglibs = new File(PATH_TO_TAGLIBS).toURI().toURL();
URLClassLoader newClassLoader = new URLClassLoader(new URL[]{urlTaglibs},currentClassLoader);
Thread.currentThread().setContextClassLoader(newClassLoader);
server.start();
You should also add it to java start command line argument.
Two step:
1)add annotation support for the server
//Enable parsing of jndi-related parts of web.xml and jetty-env.xml, #server is
org.eclipse.jetty.webapp.Configuration.ClassList classlist = org.eclipse.jetty.webapp.Configuration.ClassList.setServerDefault(server);
classlist.addAfter("org.eclipse.jetty.webapp.FragmentConfiguration", "org.eclipse.jetty.plus.webapp.EnvConfiguration", "org.eclipse.jetty.plus.webapp.PlusConfiguration");
classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration", "org.eclipse.jetty.annotations.AnnotationConfiguration");
2) add the follow attribute to the WebAppContext
context.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",".*/[^/]*servlet-api-[^/]*\\.jar$|.*/javax.servlet.jsp.jstl-.*\\.jar$|.*/org.apache.taglibs.taglibs-standard-impl-.*\\.jar$");