Причал не загружает никаких сервлетов - PullRequest
0 голосов
/ 26 июня 2019

Я использую OpenJRE 11 и Jetty 9, установленные на Ubuntu Server LTS. С этим источником:

$ find .
./build.gradle
./gradlew
./src
./src/main
./src/main/java
./src/main/java/com.example
./src/main/java/com.example/servlet
./src/main/java/com.example/servlet/ExampleServlet.java
./src/main/webapp
./src/main/webapp/WEB-INF
./src/main/webapp/WEB-INF/jetty-web.xml
./src/main/webapp/WEB-INF/web.xml

build.gradle:

plugins {
    id 'java'
    id 'war'
}

repositories {
    jcenter()
}

group 'com.example'
version '0.1'

// For Ubuntu's openjdk-11-jre-headless
sourceCompatibility = 1.11

dependencies {
    def jsp_dep = 'org.eclipse.jetty:apache-jsp:9.4.15.v20190215'
    if (gradle.startParameter.taskNames.contains('war')) {
        // Bundled in Ubuntu's libjetty9-java so not embedded
        compileOnly jsp_dep
    }

    // This should not need to be 'implementation'.
    // When hosted in Jetty, this alone is enough to support JSTL. This is a thin reference to
    // org.apache.taglibs:taglibs-standard-{spec,impl}:1.2.5
    implementation 'org.eclipse.jetty:apache-jstl:9.4.15.v20190215'
}

ExampleServlet:

package com.example.servlet;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/example")
public class ExampleServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
    }
}

Пристань-web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!-- configure-9_4 is missing -->
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">

</Configure>

web.xml:

<?xml version="1.0" encoding="UTF-8"?>

<!-- https://download.oracle.com/otn-pub/jcp/servlet-4-final-eval-spec/servlet-4_0_FINAL.pdf
-->

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                             http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">
</web-app>

Компиляция и установка:

$ ./gradlew war

BUILD SUCCESSFUL in 1s
2 actionable tasks: 2 executed

$ unzip -l build/libs/jetty-example-0.1.war
Archive:  build/libs/jetty-example-0.1.war
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  2019-06-26 14:08   META-INF/
       25  2019-06-26 14:08   META-INF/MANIFEST.MF
        0  2019-06-26 14:08   WEB-INF/
        0  2019-06-26 14:08   WEB-INF/classes/
        0  2019-06-26 14:08   WEB-INF/classes/com/
        0  2019-06-26 14:08   WEB-INF/classes/com/example/
        0  2019-06-26 14:08   WEB-INF/classes/com/example/servlet/
      696  2019-06-26 14:08   WEB-INF/classes/com/example/servlet/ExampleServlet.class
        0  2019-06-26 14:08   WEB-INF/lib/
    12585  2019-05-04 18:20   WEB-INF/lib/apache-jstl-9.4.15.v20190215.jar
    40153  2019-04-15 11:56   WEB-INF/lib/taglibs-standard-spec-1.2.5.jar
   206430  2019-04-15 11:56   WEB-INF/lib/taglibs-standard-impl-1.2.5.jar
      255  2019-06-26 13:55   WEB-INF/jetty-web.xml
      444  2019-06-26 14:03   WEB-INF/web.xml
---------                     -------
   260588                     14 files

$ mv jetty-example-0.1.war root.war
$ chmod 644 root.war
# chown jetty:adm root.war
# mv root.war /var/lib/jetty9/webapps/

# ls -la /tmp/systemd-private-*jetty9.service*/tmp/*root.war*
total 12
drwxr-xr-x 3 jetty jetty 4096 Jun 26 14:08 .
drwxrwxrwt 6 root  root  4096 Jun 26 14:08 ..
drwxr-xr-x 2 jetty jetty 4096 Jun 26 14:08 jsp

При доступе к 127.0.0.1:8080/example я получаю страницу Jetty по умолчанию 404, что наводит меня на мысль, что сканирование пакетов не происходит по умолчанию. В / var / log / syslog я получаю следующие сообщения:

Jun 26 14:07:07 web jetty9[475]: 2019-06-26 14:07:07.980:INFO:oejshC.root:Scanner-0: Warning: No org.apache.tomcat.JarScanner set in ServletContext. Falling back to default JarScanner implementation.
Jun 26 14:07:08 web jetty9[475]: 2019-06-26 14:07:08.162:INFO:oajs.TldScanner:Scanner-0: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Jun 26 14:07:08 web jetty9[475]: 2019-06-26 14:07:08.204:INFO:oejsh.ContextHandler:Scanner-0: Started o.e.j.w.WebAppContext@156a87be{root,/,file:///var/lib/jetty9/webapps/root/,AVAILABLE}{/root}
Jun 26 14:07:08 web jetty9[475]: 2019-06-26 14:07:08.280:INFO:oejsh.ContextHandler:Scanner-0: Stopped o.e.j.w.WebAppContext@7f3b84b8{root,/,null,UNAVAILABLE}{/root.war}
Jun 26 14:08:29 web jetty9[475]: 2019-06-26 14:08:29.532:INFO:oeja.AnnotationConfiguration:Scanner-0: Scanning elapsed time=28ms
Jun 26 14:08:29 web jetty9[475]: 2019-06-26 14:08:29.564:INFO:oejshC.root:Scanner-0: Warning: No org.apache.tomcat.JarScanner set in ServletContext. Falling back to default JarScanner implementation.
Jun 26 14:08:29 web jetty9[475]: 2019-06-26 14:08:29.725:INFO:oajs.TldScanner:Scanner-0: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Jun 26 14:08:29 web jetty9[475]: 2019-06-26 14:08:29.782:INFO:oejsh.ContextHandler:Scanner-0: Started o.e.j.w.WebAppContext@42e87462{root,/,file:///var/lib/jetty9/webapps/root/,AVAILABLE}{/root.war}

Почему сканирование jar по умолчанию не работает и как я могу это исправить?

1 Ответ

0 голосов
/ 07 июля 2019

Как оказалось: сломано не сканирование пакетов;это был конфликтный контекст.Почему-то Джетти считает, что два перекрывающихся контекста должны молча провалиться.В моем конкретном случае существовал каталог по умолчанию root, содержащий образец веб-приложения в Jetty.Удаление, которое решило проблему.

...