问题
I'm running into a problem that doesn't seem to be addressed by the similar questions.
I have an app that embeds Jetty, using SpringMVC, JSPs and taglibs. I use a maven plugin to generate a jar, bundle all the dependent jars into a directory and create a manifest.
When I run the app using the jar (eg. java -jar app.jar) everything works fine until I try to load a JSP that specifies <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
or any other taglib for that matter.
If I run java and specify the classpath on the command line and name my main class explicitly it all works. I've verified that the Class-Path inside my apps jar MANIFEST.MF is correct.
So far I've come up with 2 work-arounds that I would rather avoid. Have my launch script generate the classpath and put it on the command line. Or, pull the .tld files out of the Jetty jsp-api package and make them available as regular files which allows me to specify them as taglibs.
My understanding is that Jasper is supposed to tear through all Jar's all the classpath looking for tld files? When specifying the jars on the command line as part of the classpath it works, but when the class path is specified in my app's jar it fails.
回答1:
Found the solution. Turns out when embedding Jetty, and not using it to load a web application, some things just don't work as its not standard convention. Extracting the tld files into src/main/resources/META-INF/tld allowed them to be found at runtime when the class path is specified in the jar.
回答2:
I'm not sure about the specifics of Jetty and how it is supposed to work, but normally it should suffice to just drop JSTL JAR file in /WEB-INF/lib
folder of the webapp. Is it there?
A normal servletcontainer doesn't scan the %CLASSPATH%
environment variable nor the Class-Path
entry in any of the JARs to search for webapp-specific dependencies. Instead, it will just load all JARs in the /WEB-INF/lib
according the servlet spec.
The %CLASSPATH%
environment variable is by default only used when you execute java
or javac
command without the -cp
, -classpath
and -jar
arguments. The Class-Path
entry in JAR is only used when you execute the JAR in question using -jar
argument. But the webapp at its whole own isn't executed by java -jar
. It's loaded and executed by the servletcontainer itself according the servlet spec.
来源:https://stackoverflow.com/questions/6020495/embedded-jetty-fails-to-load-jsp-taglibs-when-classpath-specified-in-jar