码头 9.0 绝对 URI:无法解析 http://java.sun.com/jsp/jstl/core



我正在使用

  • 9号码头嵌入。
  • 马文
  • 爪哇 1.7
  • JSTL

当我在 Eclipse 中运行我的应用程序并浏览到包含 JSTL 标签的网页时,它工作正常。 当我将其捆绑在可执行 jar 中并从 cmd 提示符运行时,我得到

org.apache.jasper.JasperException:/jsp/pcReport.jsp(4,62) PWC6188:绝对 uri: http://java.sun.com/jsp/jstl/core 无法在 Web 或与此应用程序一起部署的 jar 文件中解析.xml

我的依赖项

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>
    <dependency>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-webapp</artifactId>
        <version>9.0.6.v20130930</version>
    </dependency>
    <dependency>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>jsp-2.1-glassfish</artifactId>
        <version>2.1.v20100127</version>
    </dependency>

我的插件

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>com.pricemon.server.Main</mainClass>
                        <classpathPrefix>webapp/WEB-INF/lib/</classpathPrefix>
                        <addClasspath>true</addClasspath>
                    </manifest>
                    <manifestEntries>
                        <Class-Path>etc/</Class-Path>
                    </manifestEntries>
                </archive>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <descriptors>
                    <descriptor>assembly.xml</descriptor>
                </descriptors>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

网络.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    version="2.5">
    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>

我在 WEB-INF/lib 下有我的 JSTL jar,它在我的清单类路径上

我只是无法弄清楚为什么这在 eclipse 下运行时有效,但在从可执行 jar 运行时不起作用。我还尝试在启动时手动添加到类路径,但没有任何效果

java -classpath ./jstl-1.2.jar -jar app.jar

我错过了一些明显的东西吗!?

我遇到了同样的问题,但最近没有找到答案。我不得不调试玻璃鱼代码来解决它。我希望下面的解释可以帮助其他人。

关于依赖关系,要使用带有玻璃鱼的 JSP 运行,您需要:

<dependency>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-jsp</artifactId>
    <version>9.2.3.v20140905</version>
</dependency>
<dependency>
    <groupId>org.eclipse.jetty.toolchain</groupId>
    <artifactId>jetty-jsp-jdt</artifactId>
    <version>2.3.3</version>
</dependency>

即使你有一罐JSLT 1.2(javax.servlet.jsp.jstl.jar可能来自玻璃鱼),你的嵌入式Jetty也无法加载核心的原因是因为TldScanner类,包括在JSP的玻璃鱼罐中。需要明确的是,这个类有一些静态的,比如:

197    static {
198        systemUrisJsf.add("http://java.sun.com/jsf/core");
199        systemUrisJsf.add("http://java.sun.com/jsf/html");
200        systemUris.add("http://java.sun.com/jsp/jstl/core");
201    }

它不会在 JAR 中加载 TLD,因为

515    private void mapTldLocation(String resourcePath, TldInfo tldInfo,
516                                boolean isLocal) {
517
518        String uri = tldInfo.getUri();
519        if (uri == null) {
520            return;
521        }
522
523        if ((isLocal
524                // Local tld files override the tlds in the jar files,
525                // unless it is in a system jar (except when using myfaces)
526                && mappings.get(uri) == null
527                && !systemUris.contains(uri)
528                && (!systemUrisJsf.contains(uri) || useMyFaces)
529            ) ||
530            (!isLocal
531                // Jars are scanned bottom up, so jars in WEB-INF override
532                // thos in the system (except when using myfaces)
533                && (mappings.get(uri) == null
534                    || systemUris.contains(uri)
535                    || (systemUrisJsf.contains(uri) && !useMyFaces)
536                   )
537            )
538           ) {
            ...

如果 url 是"http://java.sun.com/jsp/jstl/core"并且存储在本地 jar 中,则无法加载您的 TLD。要使其不是本地的,应用程序必须由父级包含 JSTL jar 的类装入器装入。简而言之,您需要修改代码以将WebAppContext初始化为如下所示:

  ...
  WebAppContext webapp = new WebAppContext();
  // classURLs may contains URL to WEB-INF/classes or WEB-INF/lib/additional_jar of you web app
  URLClassLoader classLoader = new URLClassLoader(classURLs.toArray(new URL[classURLs.size()]),
        Thread.currentThread().getContextClassLoader());
    webapp.setClassLoader(classLoader);
  ...
  ContextHandlerCollection contextCollection = new ContextHandlerCollection();
  contextCollection.addHandler(webapp);
  ...
  Server server = new Server(threadPool);
  server.setHandler(contextCollection);
  server.start();
  ...

如果这没有帮助,我想了解您如何将 Jetty 嵌入您的应用程序中。

您有一个冲突/重复的 JSTL 工件。

简化依赖关系。

<dependencies>
  <!-- Meta Dependency - adds JSP support to the same version of Jetty -->
  <dependency>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-jsp</artifactId>
    <version>9.0.6.v20130930</version>
  </dependency>
  <!-- NOT NEEDED
  <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
    <version>1.2</version>
  </dependency> -->
  <dependency>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-webapp</artifactId>
    <version>9.0.6.v20130930</version>
  </dependency>
  <!-- NOT NEEDED
  <dependency>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>jsp-2.1-glassfish</artifactId>
    <version>2.1.v20100127</version>
 </dependency> -->
</dependency>

你可以看到我们不使用 JSTL 工件和 org.mortbay.jetty 提供的 jsp 支持级别。
Jetty 提供了一个元依赖项来拉入工件,以支持与 jetty-webapp 工件相同版本的 Jetty 上的 JSP。

你应该使用:

    <dependency>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>apache-jstl</artifactId>
        <version>${jetty-version}</version>
    </dependency>

而不是:

 <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
    <version>1.2</version>
</dependency>

我也遇到了同样的问题,但在我做出更改后它被吹了。

最新更新