Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Jetty fails to start because of a problem in jetty.xml

Welcome to the users list.

First, you really do not want to be managing the XML files.
Here's an example of using Jetty 9 with it's split of two directories ${jetty.home} and ${jetty.base}.
We follow the home vs base concepts that all other web containers follow.
Where home is the binaries, and base is your configuration.

You start by downloading the jetty-home archive (tarball or zip)
This is the most fundamental image for running standalone Jetty.
The older jetty-distribution archive is just jetty-home with the demo-base example added to it.

$ mkdir jetty-stuff
$ cd jetty-stuff
$ tar -zxvf jetty-home-9.4.30.v20200611.tar.gz
$ cd jetty-home-9.4.30.v20200611
$ export JETTY_HOME=`pwd`

At this point you have a jetty-stuff/jetty-home-9.4.30.v20200611/ directory.

IMPORTANT: Leave this directory alone, don't change it, don't edit it, don't add things to it, don't delete things from it, etc..
Consider this directory to be read-only.

The jetty-stuff/jetty-home-9.4.30.v20200611/ is your ${jetty.home} directory.
It has all of the pieces that make up the standalone jetty experience, but no configuration.

Now we have to make our ${jetty.base} directory.
This directory should not be nested inside or outside of the ${jetty.home} directory.

$ cd jetty-stuff
$ mkdir mybase
$ cd mybase
$ java -jar $JETTY_HOME/start.jar --create-startd --add-to-start=http,deploy,webapp,threadpool
MKDIR : ${jetty.base}/start.d
INFO  : webapp          transitively enabled, ini template available with --add-to-start=webapp
INFO  : server          transitively enabled, ini template available with --add-to-start=server
INFO  : security        transitively enabled
INFO  : servlet         transitively enabled
INFO  : http            initialized in ${jetty.base}/start.d/http.ini
INFO  : threadpool      initialized in ${jetty.base}/start.d/threadpool.ini
INFO  : bytebufferpool  transitively enabled, ini template available with --add-to-start=bytebufferpool
INFO  : deploy          initialized in ${jetty.base}/start.d/deploy.ini
MKDIR : ${jetty.base}/webapps
INFO  : Base directory was modified
$ tree -F
.
├── start.d/
│   ├── deploy.ini
│   ├── http.ini
│   └── threadpool.ini
└── webapps/


At this point you have a basic configured ${jetty.base} without any specific webapps deployed.
You can see your configuration by using --list-config ...

$ cd jetty-stuff/mybase
$ java -jar $JETTY_HOME/start.jar --list-config
Java Environment:
-----------------
 java.home = /home/joakim/java/jvm/jdk-11.0.7+10 (null)
 java.vm.vendor = AdoptOpenJDK (null)
 java.vm.version = 11.0.7+10 (null)
 java.vm.name = OpenJDK 64-Bit Server VM (null)
 java.vm.info = mixed mode (null)
 java.runtime.name = OpenJDK Runtime Environment (null)
 java.runtime.version = 11.0.7+10 (null)
 java.io.tmpdir = /tmp (null)
 user.dir = /home/joakim/demo/jetty-stuff/mybase (null)
 user.language = en (null)
 user.country = US (null)

Jetty Environment:
-----------------
 jetty.version = 9.4.30.v20200611
 jetty.tag.version = master
 jetty.home = /home/joakim/demo/jetty-stuff/jetty-home-9.4.30.v20200611
 jetty.base = /home/joakim/demo/jetty-stuff/mybase

Config Search Order:
--------------------
 <command-line>
 ${jetty.base} -> /home/joakim/demo/jetty-stuff/mybase
 ${jetty.home} -> /home/joakim/demo/jetty-stuff/jetty-home-9.4.30.v20200611


JVM Arguments:
--------------
 (no jvm args specified)

System Properties:
------------------
 (no system properties specified)

Properties:
-----------
 java.version = 11.0.7
 java.version.major = 11
 java.version.micro = 7
 java.version.minor = 0
 java.version.platform = 11
 jetty.base = /home/joakim/demo/jetty-stuff/mydemobase
 jetty.base.uri = file:///home/joakim/demo/jetty-stuff/mydemobase
 jetty.home = /home/joakim/demo/jetty-stuff/jetty-home-9.4.30.v20200611
 jetty.home.uri = file:///home/joakim/demo/jetty-stuff/jetty-home-9.4.30.v20200611

Jetty Server Classpath:
-----------------------
Version Information on 11 entries in the classpath.
Note: order presented here is how they would appear on the classpath.
      changes to the --module=name command line options will be reflected here.
 0:                    3.1.0 | ${jetty.home}/lib/servlet-api-3.1.jar
 1:                 3.1.0.M0 | ${jetty.home}/lib/jetty-schemas-3.1.jar
 2:         9.4.30.v20200611 | ${jetty.home}/lib/jetty-http-9.4.30.v20200611.jar
 3:         9.4.30.v20200611 | ${jetty.home}/lib/jetty-server-9.4.30.v20200611.jar
 4:         9.4.30.v20200611 | ${jetty.home}/lib/jetty-xml-9.4.30.v20200611.jar
 5:         9.4.30.v20200611 | ${jetty.home}/lib/jetty-util-9.4.30.v20200611.jar
 6:         9.4.30.v20200611 | ${jetty.home}/lib/jetty-io-9.4.30.v20200611.jar
 7:         9.4.30.v20200611 | ${jetty.home}/lib/jetty-security-9.4.30.v20200611.jar
 8:         9.4.30.v20200611 | ${jetty.home}/lib/jetty-servlet-9.4.30.v20200611.jar
 9:         9.4.30.v20200611 | ${jetty.home}/lib/jetty-webapp-9.4.30.v20200611.jar
10:         9.4.30.v20200611 | ${jetty.home}/lib/jetty-deploy-9.4.30.v20200611.jar

Jetty Active XMLs:
------------------
 ${jetty.home}/etc/jetty-bytebufferpool.xml
 ${jetty.home}/etc/jetty-threadpool.xml
 ${jetty.home}/etc/jetty.xml
 ${jetty.home}/etc/jetty-webapp.xml
 ${jetty.home}/etc/jetty-deploy.xml
 ${jetty.home}/etc/jetty-http.xml

This shows you that the XML is used from ${jetty.home}, as-is.

As for the modules I picked "http,deploy.webapp,threadpool" those are just some of the predefined modules present on jetty-home.

You can list the available modules with --list-modules

$ cd jetty-stuff/mybase
$ java -jar $JETTY_HOME/start.jar --list-modules

Some other common modules are ..
 * `resources` for making a `${jetty.base}/resources/` directory available on the server classpath
 * `ext` for making a ${jetty.base}/lib/ext/*.jar files available on the server classpath.
 * `console-capture` for capturing all console output to a logging file
 * `annotations` for enabling annotation scanning of bytecode for Servlet annotations
 * `gzip` for enabling gzip compression of response, and gzip decompression of requests.
 * `https` for enabling an HTTPS connector
 * `http2` for enabling an HTTP2 connector

The modules themselves can have ...
 * Dependencies on other modules
 * Properties for configuring the module
 * XML (which is properly ordered based on other XML)
 * Required libraries (downloaded if not present, after a license check with you)
 * Required directories (created if not present)

You can use the `--add-to-start=<modules>` at any point to add more modules to your configuration.
To remove a module, just delete the file in ${jetty.base}/start.d/ that enables the module.

Note that only modules you specifically enable are present in the start.d directory, transitive modules from those specifically mentioned are also enabled, but not represented by a file in the start.d directory.

An example of that would be the "server" module.
You can see this at the end of the output from `--list-modules`

$ cd jetty-stuff/mybase
$ java -jar $JETTY_HOME/start.jar --list-modules
...(snip)...
Enabled Modules:
================
    0) bytebufferpool  transitive provider of bytebufferpool for server
                       init template available with --add-to-start=bytebufferpool
    1) threadpool      ${jetty.base}/start.d/threadpool.ini
    2) server          transitive provider of server for http
                       transitive provider of server for servlet
                       init template available with --add-to-start=server
    3) security        transitive provider of security for webapp
    4) servlet         transitive provider of servlet for webapp
    5) webapp          transitive provider of webapp for deploy
                       init template available with --add-to-start=webapp
    6) deploy          ${jetty.base}/start.d/deploy.ini
    7) http            ${jetty.base}/start.d/http.ini


The text "init template available" means that there are properties that can be configured for that module.

You can add `server` after the fact with ...

$ cd jetty-stuff/mybase
$ java -jar $JETTY_HOME/start.jar --list-modules
INFO  : server          initialized in ${jetty.base}/start.d/server.ini
INFO  : Base directory was modified


Now let's take a look at your configuration details, and adjust some threadpool numbers.

$ cat start.d/threadpool.ini
# ---------------------------------------
# Module: threadpool
# Enables the Server thread pool.
# ---------------------------------------
--module=threadpool


### Server Thread Pool Configuration
## Minimum Number of Threads
#jetty.threadPool.minThreads=10

## Maximum Number of Threads
#jetty.threadPool.maxThreads=200

## Number of reserved threads (-1 for heuristic)
# jetty.threadPool.reservedThreads=-1

## Thread Idle Timeout (in milliseconds)
#jetty.threadPool.idleTimeout=60000

## Whether to Output a Detailed Dump
#jetty.threadPool.detailedDump=false

Lets edit that file and uncomment the minThreads and detailedDump and set them to non-default values.
Such as minThreads of 16 and detailedDump=true
$ edit start.d/threadpool.ini
$ java -jar $JETTY_HOME/start.jar --list-config | grep thread
 jetty.threadPool.detailedDump = false
 jetty.threadPool.minThreads = 16
 ${jetty.home}/etc/jetty-threadpool.xml

Now copy some of your webapps into place ...

$ cp /path/to/myapp.war jetty-stuff/mybase/webapps/

And run Jetty with server dump enabled (to see what the server looks like after it has loaded)
The use of `jetty.server.dumpAfterStart=true` is just setting a property on the command line (vs declaring it in the start.d/*.ini files)
You can test any property from the command line before you commit to using it in your configuration files.
You can even override the property in the configuration files with the command line.
The `Config Search Order` from `--list-config` tells you how things are found.
This is not limited to just properties, but also applies to libraries and xml files!
Example: If you provide a highly customized XML your ${jetty.base}/etc/ it will be used over the one in ${jetty.home}/etc/

$ cd jetty-stuff/mybase
$ java -jar $JETTY_HOME/start.jar jetty.server.dumpAfterStart=true
...(snip lots of output)...

Now you have a running server instance based on $JETTY_HOME with configuration from ${jetty.base} (which is jetty-stuff/mybase) here.

Now, why bother with having these directories separate?
Why does ${jetty.base} exist?
As I mentioned above, i'll get to it.

Easily change versions of Jetty!

Example with what you have above ...

$ jetty-stuff
$ tar -zxvf jetty-home-9.4.29.v20200521.tar.gz
$ cd mybase
$ java -jar ../jetty-home-9.4.29.v20200521/start.jar

Done, you've just changed versions of Jetty, and had no configurations to edit / copy over / etc ...

You can even go to Jetty 10 with minimal hassle.
(Going to Jetty 11 would require you to use the new Jakarta EE 9 namespace in your war files though)

In short, the recommended approach is to not manage XML, use Properties and modules.

Joakim Erdfelt / joakim@xxxxxxxxxxx


On Thu, Jul 16, 2020 at 1:02 AM Netta STEINBERG <NSTEINBERG@xxxxxxxxx> wrote:
Hi all,

My name is Netta and I would appreciate your help with this:

I have the following jetty.xml file:

Here is its content:
<?xml version="1.0"?>

<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">

<!-- =============================================================== -->
<!-- Configure the Jetty Server                                      -->
<!--                                                                 -->
<!-- Documentation of this file format can be found at:              -->
<!-- http://wiki.eclipse.org/Jetty/Reference/jetty.xml_syntax        -->
<!--                                                                 -->
<!-- =============================================================== -->


<Configure id="Server" class="org.eclipse.jetty.server.Server">

    <!-- =========================================================== -->
    <!-- Server Thread Pool                                          -->
    <!-- =========================================================== -->
    <Set name="ThreadPool">
      <!-- Default queued blocking threadpool -->
      <New class="org.eclipse.jetty.util.thread.QueuedThreadPool">
        <Set name="minThreads">10</Set>
        <Set name="maxThreads">10000</Set>
        <Set name="detailedDump">false</Set>
      </New>
    </Set>

    <!-- =========================================================== -->
    <!-- Set connectors                                              -->
    <!-- =========================================================== -->

    <Call name="addConnector">
      <Arg>
          <New class="org.eclipse.jetty.server.bio.SocketConnector">
            <Set name="host"><SystemProperty name="jetty.host" /></Set>
            <Set name="port"><SystemProperty name="jetty.port" default="8983"/></Set>
            <Set name="maxIdleTime">50000</Set>
            <Set name="lowResourceMaxIdleTime">1500</Set>
            <Set name="statsOn">false</Set>
            <Set name="requestHeaderSize">1000000</Set>
            <Set name="requestBufferSize">1000000</Set>
          </New>
      </Arg>
    </Call>

    <!-- =========================================================== -->
    <!-- Set handler Collection Structure                            -->
    <!-- =========================================================== -->
    <Set name="handler">
      <New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
        <Set name="handlers">
         <Array type="org.eclipse.jetty.server.Handler">
           <Item>
             <New id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>
           </Item>
           <Item>
             <New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
           </Item>
           <Item>
             <New id="RequestLog" class="org.eclipse.jetty.server.handler.RequestLogHandler"/>
           </Item>
         </Array>
        </Set>
      </New>
    </Set>
   
    <!-- =========================================================== -->
    <!-- extra options                                               -->
    <!-- =========================================================== -->
    <Set name="stopAtShutdown">true</Set>
    <Set name="sendServerVersion">false</Set>
    <Set name="sendDateHeader">false</Set>
    <Set name="gracefulShutdown">1000</Set>
    <Set name="dumpAfterStart">false</Set>
    <Set name="dumpBeforeStop">false</Set>

    <Call name="addBean">
      <Arg>
        <New id="DeploymentManager" class="org.eclipse.jetty.deploy.DeploymentManager">
          <Set name="contexts">
            <Ref id="Contexts" />
          </Set>
          <Call name="setContextAttribute">
            <Arg>org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern</Arg>
            <Arg>.*/servlet-api-[^/]*\.jar$</Arg>
          </Call>          
        </New>
      </Arg>
    </Call>
   
    <Ref id="DeploymentManager">
      <Call name="addAppProvider">
        <Arg>
          <New class="org.eclipse.jetty.deploy.providers.ContextProvider">
            <Set name="monitoredDirName"><SystemProperty name="jetty.home" default="."/>/contexts</Set>
            <Set name="scanInterval">0</Set>
          </New>
        </Arg>
      </Call>
    </Ref>

</Configure>

It worked until we decided to upgrade the jetty version from 8.1.10.v20130312 to 9.4.29.v20200521. Now the server fails to start.
I'm trying to change it so it will
a - work (i.e. fit the API changes that happen between the versions)
b - will be as close to the original file as possible (since I don't know the consequences of changing one part or another, the impact on performance it will have, etc.)

This is what I have so far (major changes are in bold):

Here is the content:
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">

<!-- =============================================================== -->
<!-- Configure the Jetty Server                                      -->
<!--                                                                 -->
<!-- Documentation of this file format can be found at:              -->
<!-- http://wiki.eclipse.org/Jetty/Reference/jetty.xml_syntax        -->
<!--                                                                 -->
<!-- =============================================================== -->


<Configure id="Server" class="org.eclipse.jetty.server.Server">

    <!-- =========================================================== -->
    <!-- Server Thread Pool                                          -->
    <!-- =========================================================== -->
<!--    <Set name="ThreadPool">-->
          <!-- Default queued blocking threadpool -->
<!--      <New class="org.eclipse.jetty.util.thread.QueuedThreadPool">-->        There is no setThreadPool method in the new API
<!--        <Set name="minThreads">10</Set>-->
<!--        <Set name="maxThreads">10000</Set>-->
<!--        <Set name="detailedDump">false</Set>-->
<!--      </New>-->
<!--    </Set>-->

    <!-- =========================================================== -->
    <!-- Set connectors                                              -->
    <!-- =========================================================== -->

    <Call name="addConnector">
        <Arg>
            <New class="org.eclipse.jetty.server.ServerConnector">
                <Arg name="server"><Ref refid="Server" /></Arg>
                <Set name="host"><SystemProperty name="jetty.host" /></Set>
                <Set name="port"><SystemProperty name="jetty.port" default="8983"/></Set>
                <Set name="idleTimeout">50000</Set>
<!--                <Set name="lowResourceMaxIdleTime">1500</Set>-->
<!--                <Set name="statsOn">false</Set>-->                                                                   Some fields are not available anymore
<!--                <Set name="requestHeaderSize">1000000</Set>-->
<!--                <Set name="requestBufferSize">1000000</Set>-->
            </New>
        </Arg>
    </Call>

    <!-- =========================================================== -->
    <!-- Set handler Collection Structure                            -->
    <!-- =========================================================== -->
    <Set name="handler">
      <New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
        <Set name="handlers">
         <Array type="org.eclipse.jetty.server.Handler">
           <Item>
             <New id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>
           </Item>
           <Item>
             <New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
           </Item>
           <Item>
             <New id="RequestLog" class="org.eclipse.jetty.server.handler.RequestLogHandler"/>
           </Item>
         </Array>
        </Set>
      </New>
    </Set>

    <!-- =========================================================== -->
    <!-- extra options                                               -->
    <!-- =========================================================== -->
    <Set name="stopAtShutdown">true</Set>
<!--    <Set name="sendServerVersion">false</Set>-->
<!--    <Set name="sendDateHeader">false</Set>-->
    <Set name="stopTimeout">1000</Set>
    <Set name="dumpAfterStart">false</Set>
    <Set name="dumpBeforeStop">false</Set>

    <Call name="addBean">
      <Arg>
        <New id="DeploymentManager" class="org.eclipse.jetty.deploy.DeploymentManager">
          <Set name="contexts">
            <Ref refid="Contexts" />
          </Set>
          <Call name="setContextAttribute">
            <Arg>org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern</Arg>
            <Arg>.*/servlet-api-[^/]*\.jar$</Arg>
          </Call>    
        </New>
      </Arg>
    </Call>
   
    <Ref refid="DeploymentManager">
      <Call name="addAppProvider">
        <Arg>
          <New class="org.eclipse.jetty.deploy.providers.ScanningAppProvider">                                                      ContextProvider is not available anymore. I chose ScanningAppProvider because
            <Set name="monitoredDirName"><SystemProperty name="jetty.home" default="."/>/contexts</Set>                      it seems to have a similar interface (a similar behavior - monitoredDirName, scanInterval)
            <Set name="scanInterval">0</Set>
          </New>
        </Arg>
      </Call>
    </Ref>

</Configure>


I have a few questions:

1. The old API had a setThreadPool method for the server. The new one hasn't. Instead, it has a constructor that accept a ThreadPool as argument. My problem is that in the jetty.xml file there is no way to give the server an argument, since the configure element doesn't support the Arg element.
What can I do?
Is there a way to the "set" the server's ThreadPool in version 9.4.29.v20200521?
Is there a way to define a server constructor with a ThreadPool argument?
Can I set the ThreadPool fields somehow?

2. The ScanningAppProvider is causing problems. I get the following error when I try to start my application:
No suitable constructor: <New class="org.eclipse.jetty.deploy.providers.ScanningAppProvider"><Set name="monitoredDirName"><SystemProperty name="jetty.home" default="."/>/contexts</Set><Set name="scanInterval">0</Set></New> on DeploymentManager@8383a14{STOPPED}
 java.lang.IllegalStateException: No suitable constructor: <New class="org.eclipse.jetty.deploy.providers.ScanningAppProvider"><Set name="monitoredDirName"><SystemProperty name="jetty.home" default="."/>/contexts</Set><Set name="scanInterval">0</Set></New> on DeploymentManager@8383a14{STOPPED}
        at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.newObj(XmlConfiguration.java:1036)
        at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.itemValue(XmlConfiguration.java:1561)
        at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.value(XmlConfiguration.java:1462)
        at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.access$600(XmlConfiguration.java:416)
        at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration$Args.<init>(XmlConfiguration.java:1720)
        at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration$Args.<init>(XmlConfiguration.java:1707)
        at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.call(XmlConfiguration.java:963)
        at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:536)
        at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.refObj(XmlConfiguration.java:1084)
        at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:551)
        at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:452)
        at org.eclipse.jetty.xml.XmlConfiguration.configure(XmlConfiguration.java:385)

As far as I can tell, I used the correct xml structure, the correct names of the class and methods (at this part, when comparing to the previous version that worked, all I changed was the class name, from ContextProvider to ScanningAppProvider, so I don't understand why I get this error.


I would appreciate any and all comments, suggestions and solutions.

Best regards,
Netta_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jetty-users

Back to the top