当前位置: 首页 > 知识库问答 >
问题:

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

戎元忠
2023-03-14

我在用

  • 嵌入式Jetty 9。
  • Maven
  • Java 1.7
  • JSTL

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

    <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 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>
java -classpath ./jstl-1.2.jar -jar app.jar

我是不是漏掉了一些明显的东西!?

共有1个答案

习和通
2023-03-14

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

关于依赖关系,要使用glassfish运行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>

即使您有一个JSLT1.2的jar(来自glassfish的javax.servlet.jsp.jstl.jar),嵌入式Jetty也无法加载核心的原因是TldScanner类包括在用于JSP的glassfish jar中。明确地说,这个类有一些静态特性,比如:

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    }
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           ) {
            ...
  ...
  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();
  ...
 类似资料: