Jetty 9 The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved

前端 未结 3 710
故里飘歌
故里飘歌 2020-12-17 04:14

I\'m using

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

When I run my app in Eclipse and browse to my webpage which contain

相关标签:
3条回答
  • 2020-12-17 04:46

    You should use:

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

    Instead of:

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

    I also meet same problem but it was blown after I make that change.

    0 讨论(0)
  • 2020-12-17 04:50

    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.

    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>
    

    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    }
    

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

    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();
      ...
    

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

    0 讨论(0)
  • You have a conflicting / duplicate artifact for JSTL.

    Simplify your dependencies.

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

    You can see that we don't use the JSTL artifact and org.mortbay.jetty provided jsp support level.
    Jetty has provided a meta dependency to pull in the artifacts to support JSP on the same version of Jetty as your jetty-webapp artifact.

    0 讨论(0)
提交回复
热议问题