Jetty 9绝对的uri:http://java.sun.com/jsp/jstl/core无法解析 [英] Jetty 9 The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved

查看:1710
本文介绍了Jetty 9绝对的uri:http://java.sun.com/jsp/jstl/core无法解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用


  • Jetty 9 embedded。

  • Maven

  • Java 1.7

  • JSTL

  • Jetty 9 embedded.
  • Maven
  • Java 1.7
  • JSTL

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

When I run my app in Eclipse and browse to my webpage which contains JSTL tags it works fine. When I bundle it in an executable jar and run from cmd prompt I get


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

org.apache.jasper.JasperException: /jsp/pcReport.jsp(4,62) PWC6188: The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application

我的依赖关系

    <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>

web.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>

我在我的Manifest类路径下的WEB-INF / lib下有我的JSTL jar

I've got my JSTL jar under WEB-INF/lib which is on my Manifest classpath

我无法弄清楚为什么在eclipse下运行时这可行,但从可执行jar运行时不会工作。我也尝试在启动时手动添加到classpath无效

I just cant figure out why this works when run under eclipse but wont work when run from executable jar. I've also tried manually adding to classpath when launching with no effect

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

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

Am I missing something obvious!?

推荐答案

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

I've run into the same problem but found no answer recently. I had to debug glassfish code to solve it. I hope the following explanation can help others.

关于依赖关系,使用带有glassfish的JSP运行你需要:

About dependencies, to run with JSP with glassfish you will need:

<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,嵌入式Jetty无法加载核心的原因(可行) 来自glassfish的javax.servlet.jsp.jstl.jar 是因为 TldScanner 包括在用于JSP的glassfish jar中的类。要清楚这个类有一些静态的:

The reason why your embedded Jetty could not load core even if you have a jar of JSLT 1.2 (propably javax.servlet.jsp.jstl.jar from glassfish) is because of TldScanner class including in glassfish jars for JSP. To be clear this class has some static like:

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,因为

And it would not load TLD in the JAR because of the block in

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           ) {
            ...

没有办法加载哟如果网址为 http://java.sun.com/jsp/jstl/core 它存储在本地jar中。要使其为NOT LOCAL,应用程序必须由父类包含JSTL jar的类加载器加载。简而言之,您需要修改代码以初始化 WebAppContext ,如下所示:

There is no way it's gonna load your TLD if the url is "http://java.sun.com/jsp/jstl/core" and it is stored in a local jar. To make it NOT LOCAL, the application must be loaded by a class loader whose parent contains the JSTL jar. In short, you need to modify code to initialize WebAppContext as something like:

  ...
  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。

If this does not help, I'd like to learn how you embed Jetty in you application.

这篇关于Jetty 9绝对的uri:http://java.sun.com/jsp/jstl/core无法解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆