web-dev-qa-db-fra.com

Changer le port par défaut de Jetty

Le port par défaut de la jetée est 8080, mais je veux changer de port par défaut pour un autre port (9999).

J'ai lu quelques tutoriels et ils m'ont dit que presque toutes les informations de configuration sont conservées par défaut dans le fichier jetty.xml, ce fichier se trouve sous $JETTY_HOME/etc/. Ensuite, modifiez la propriété jetty.port à 9999. Cependant, lorsque j'ai ouvert ce fichier, je n'ai pas pu trouver la propriété jetty.port dans le jetty.xml. J'utilise actuellement Jetty-9.2.1 et le port est à 8080.

J'ai trouvé la propriété jetty.port sous le fichier jetty-http.xml. Même si j'ai changé le port en 8090 dans le fichier jetty-http.xml, jetty fonctionne toujours sur le port 8080.

jetty.xml

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.Eclipse.org/jetty/configure_9_0.dtd">

<!-- =============================================================== -->
<!-- Documentation of this file format can be found at:              -->
<!-- http://wiki.Eclipse.org/Jetty/Reference/jetty.xml_syntax        -->
<!--                                                                 -->
<!-- Additional configuration files are available in $JETTY_HOME/etc -->
<!-- and can be mixed in. See start.ini file for the default         -->
<!-- configuration files.                                            -->
<!--                                                                 -->
<!-- For a description of the configuration mechanism, see the       -->
<!-- output of:                                                      -->
<!--   Java -jar start.jar -?                                        -->
<!-- =============================================================== -->

<!-- =============================================================== -->
<!-- Configure a Jetty Server instance with an ID "Server"           -->
<!-- Other configuration files may also configure the "Server"       -->
<!-- ID, in which case they are adding configuration to the same     -->
<!-- instance.  If other configuration have a different ID, they     -->
<!-- will create and configure another instance of Jetty.            -->
<!-- Consult the javadoc of o.e.j.server.Server for all              -->
<!-- configuration that may be set here.                             -->
<!-- =============================================================== -->
<Configure id="Server" class="org.Eclipse.jetty.server.Server">

    <!-- =========================================================== -->
    <!-- Configure the Server Thread Pool.                           -->
    <!-- The server holds a common thread pool which is used by      -->
    <!-- default as the executor used by all connectors and servlet  -->
    <!-- dispatches.                                                 -->
    <!--                                                             -->
    <!-- Configuring a fixed thread pool is vital to controlling the -->
    <!-- maximal memory footprint of the server and is a key tuning  -->
    <!-- parameter for tuning.  In an application that rarely blocks -->
    <!-- then maximal threads may be close to the number of 5*CPUs.  -->
    <!-- In an application that frequently blocks, then maximal      -->
    <!-- threads should be set as high as possible given the memory  -->
    <!-- available.                                                  -->
    <!--                                                             -->
    <!-- Consult the javadoc of o.e.j.util.thread.QueuedThreadPool   -->
    <!-- for all configuration that may be set here.                 -->
    <!-- =========================================================== -->
    <!-- uncomment to change type of threadpool
    <Arg name="threadpool"><New id="threadpool" class="org.Eclipse.jetty.util.thread.QueuedThreadPool"/></Arg>
    -->
    <Get name="ThreadPool">
      <Set name="minThreads" type="int"><Property name="threads.min" default="10"/></Set>
      <Set name="maxThreads" type="int"><Property name="threads.max" default="200"/></Set>
      <Set name="idleTimeout" type="int"><Property name="threads.timeout" default="60000"/></Set>
      <Set name="detailedDump">false</Set>
    </Get>

    <!-- =========================================================== -->
    <!-- Add shared Scheduler instance                               -->
    <!-- =========================================================== -->
    <Call name="addBean">
      <Arg>
        <New class="org.Eclipse.jetty.util.thread.ScheduledExecutorScheduler"/>
      </Arg>
    </Call>

    <!-- =========================================================== -->
    <!-- Http Configuration.                                         -->
    <!-- This is a common configuration instance used by all         -->
    <!-- connectors that can carry HTTP semantics (HTTP, HTTPS, SPDY)-->
    <!-- It configures the non wire protocol aspects of the HTTP     -->
    <!-- semantic.                                                   -->
    <!--                                                             -->
    <!-- This configuration is only defined here and is used by      -->
    <!-- reference from the jetty-http.xml, jetty-https.xml and      -->
    <!-- jetty-spdy.xml configuration files which instantiate the    -->
    <!-- connectors.                                                 -->
    <!--                                                             -->
    <!-- Consult the javadoc of o.e.j.server.HttpConfiguration       -->
    <!-- for all configuration that may be set here.                 -->
    <!-- =========================================================== -->
    <New id="httpConfig" class="org.Eclipse.jetty.server.HttpConfiguration">
      <Set name="secureScheme">https</Set>
      <Set name="securePort"><Property name="jetty.secure.port" default="8443" /></Set>
      <Set name="outputBufferSize"><Property name="jetty.output.buffer.size" default="32768" /></Set>
      <Set name="requestHeaderSize"><Property name="jetty.request.header.size" default="8192" /></Set>
      <Set name="responseHeaderSize"><Property name="jetty.response.header.size" default="8192" /></Set>
      <Set name="sendServerVersion"><Property name="jetty.send.server.version" default="true" /></Set>
      <Set name="sendDateHeader"><Property name="jetty.send.date.header" default="false" /></Set>
      <Set name="headerCacheSize">512</Set>
      <!-- Uncomment to enable handling of X-Forwarded- style headers
      <Call name="addCustomizer">
        <Arg><New class="org.Eclipse.jetty.server.ForwardedRequestCustomizer"/></Arg>
      </Call>
      -->
    </New>


    <!-- =========================================================== -->
    <!-- Set the default handler structure for the Server            -->
    <!-- A handler collection is used to pass received requests to   -->
    <!-- both the ContextHandlerCollection, which selects the next   -->
    <!-- handler by context path and virtual Host, and the           -->
    <!-- DefaultHandler, which handles any requests not handled by   -->
    <!-- the context handlers.                                       -->
    <!-- Other handlers may be added to the "Handlers" collection,   -->
    <!-- for example the jetty-requestlog.xml file adds the          -->
    <!-- RequestLogHandler after the default handler                 -->
    <!-- =========================================================== -->
    <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>
         </Array>
        </Set>
      </New>
    </Set>

    <!-- =========================================================== -->
    <!-- extra server options                                        -->
    <!-- =========================================================== -->
    <Set name="stopAtShutdown">true</Set>
    <Set name="stopTimeout">5000</Set>
    <Set name="dumpAfterStart"><Property name="jetty.dump.start" default="false"/></Set>
    <Set name="dumpBeforeStop"><Property name="jetty.dump.stop" default="false"/></Set>

</Configure>

jetty-http.xml

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.Eclipse.org/jetty/configure_9_0.dtd">

<!-- ============================================================= -->
<!-- Configure the Jetty Server instance with an ID "Server"       -->
<!-- by adding a HTTP connector.                                   -->
<!-- This configuration must be used in conjunction with jetty.xml -->
<!-- ============================================================= -->
<Configure id="Server" class="org.Eclipse.jetty.server.Server">

  <!-- =========================================================== -->
  <!-- Add a HTTP Connector.                                       -->
  <!-- Configure an o.e.j.server.ServerConnector with a single     -->
  <!-- HttpConnectionFactory instance using the common httpConfig  -->
  <!-- instance defined in jetty.xml                               -->
  <!--                                                             -->
  <!-- Consult the javadoc of o.e.j.server.ServerConnector and     -->
  <!-- o.e.j.server.HttpConnectionFactory for all configuration    -->
  <!-- that may be set here.                                       -->
  <!-- =========================================================== -->
  <Call name="addConnector">
    <Arg>
      <New class="org.Eclipse.jetty.server.ServerConnector">
        <Arg name="server"><Ref refid="Server" /></Arg>
        <Arg name="factories">
          <Array type="org.Eclipse.jetty.server.ConnectionFactory">
            <Item>
              <New class="org.Eclipse.jetty.server.HttpConnectionFactory">
                <Arg name="config"><Ref refid="httpConfig" /></Arg>
              </New>
            </Item>
          </Array>
        </Arg>
        <Set name="Host"><Property name="jetty.Host" /></Set>
        <Set name="port"><Property name="jetty.port" default="8090" /></Set>
        <Set name="idleTimeout"><Property name="http.timeout" default="30000"/></Set>
        <Set name="soLingerTime"><Property name="http.soLingerTime" default="-1"/></Set>
      </New>
    </Arg>
  </Call>

</Configure>

On m'a également conseillé d'utiliser un test d'intégration pour configurer Jetty afin d'utiliser un autre port. Il y a un integration-tests.properties fichier dans le projet. Peut-être qu'une solution consiste à définir jetty.port sur 9999 dans ce fichier?

integration-tests.properties:

Host = localhost
port = 9999
20
wag0325

ça marche si vous définissez le port lorsque vous le démarrez à partir de la ligne de commande comme ceci:

Java -jar start.jar -Djetty.port=9999
27
Magnus Lassi

Je l'ai fait dans la version Jetty 9.x. Vous devez aller dans le fichier $ JETTY_HOME/start.ini et modifier ce paramètre jetty.port . Disons que vous voulez exécuter jetty au port 9090: veuillez modifier le paramètre jetty.port dans $ JETTY_HOME/start.ini de jetty.port = 8080 à jetty.port = 9090

Ensuite, démarrez jetty en utilisant l'option "Java -jar start.jar". Ensuite, la jetée fonctionnera sur le port 9090 que sur le port 8080 par défaut. Ensuite, faites "curl -i -XGET" http: // localhost: 909 ". Cela devrait vous donner un état de 200 http. C'est tout.

8
user3348367

Mise à jour:

Sur Jetty 9.x, jetty.port est obsolète et vous pouvez utiliser jetty.http.port à la place, comme indiqué ci-dessous:

$> cd $JETTY_HOME && Java -jar start.jar -Djetty.http.port=8080
6
amey91

Sur la jetée 9.2.3.v20140905, il faut écrire dans /etc/default/jetty

# JETTY_ARGS
#   The default arguments to pass to jetty.
#   For example
JETTY_ARGS="jetty.port=8080 jetty.spdy.port=8443 jetty.secure.port=443"

mais cela ne change que le port http. Pour modifier le port https dans la jetée 9.2, créez le fichier ini $JETTY_HOME/start.d/https.ini

# Initialize module https
#
--module=https
## HTTPS Configuration
# HTTP port to listen on
https.port=8443
# HTTPS idle timeout in milliseconds
https.timeout=30000
# HTTPS Socket.soLingerTime in seconds. (-1 to disable)
# https.soLingerTime=-1

jetée 9. in /etc/default/jetty

# JETTY_ARGS
# The default arguments to pass to jetty.
# For example
JETTY_ARGS="jetty.http.port=8080 jetty.ssl.port=443"

ou paramètres de ligne de commande -Djetty.http.port=8080 -Djetty.ssl.port=443

5
sytolk

J'ai changé le port avec succès, vous pouvez essayer de modifier jetty.port dans le fichier situé à $Jetty_home/start.d/http.ini.

4
Haidong Zhang

Vous devez modifier le port http dans le fichier start.ini, car il dépassera la configuration de jetty-http.xml ou commentez simplement la ligne dans start.ini et conservez votre configuration de jetty-http.xml. Dans [jetty home] /start.ini

## HTTP port to listen on
#jetty.port=8080
3
sja

Si vous utilisez Eclipse, vous devez définir les configurations d'exécution. Lorsque vous installez jetty dans Eclipse, le port par défaut pour jetty est 808.

Vous devez donc le changer en un fichier XML. Si le problème persiste, vous devez le modifier dans les configurations d'exécution Eclipse.

J'espère que cela fonctionne, comme cela a fonctionné pour moi.

2
Haseeb Ahmad

Pour être complet sur la jetée 7, vous pouvez utiliser ceci:

Java -jar start.jar --module=http jetty.port=9080
2
Danilo Silveira