2014-07-09 13 views
14

La porta predefinita del jetty è 8080, ma desidero passare alla porta predefinita su un'altra porta (9999).Cambiare la porta predefinita Jetty

Ho letto alcuni tutorial e hanno detto che quasi tutte le informazioni di configurazione sono mantenute per default nel file jetty.xml, questo file si trova sotto $JETTY_HOME/etc/. Quindi, modificare la proprietà jetty.port a 9999. Tuttavia, quando ho aperto il file, non è stato possibile trovare la proprietà jetty.port all'interno di jetty.xml. Attualmente sto usando Jetty-9.2.1 e la porta è a 8080.

Ho trovato la proprietà jetty.port sotto il file jetty-http.xml. Anche se ho cambiato la porta a 8090 nel file pontile-http.xml, molo è ancora in esecuzione sulla porta 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> 

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

Sono stato inoltre consigliato di utilizzare un test di integrazione per configurare Jetty per l'utilizzo di un'altra porta. C'è un file integration-tests.properties all'interno del progetto. Forse una soluzione è impostare jetty.port su 9999 all'interno di questo file?

integration-tests.properties:

host = localhost 
port = 9999 
+0

modifica dell'impostazione jetty.port all'interno molo-http.xml lavorato per me. Forse hai un'altra applicazione usando la porta 9999? – slim

risposta

19

funziona se si imposta la porta quando lo si avvia dalla riga di comando in questo modo:

java -jar start.jar -Djetty.port=9999 
+0

argomento fisso. –

+0

Ciò non cambia la porta predefinita. Dopo aver eseguito questa riga, Jetty gira ancora sotto la porta 8080 quando eseguo 'java -jar start.jar'. Sto cercando un modo per modificare in modo permanente la porta predefinita. – wag0325

+0

@ wag0325 Mi stavo chiedendo se avrebbe fatto la differenza per risolvere il problema. Dopo aver aggiornato jetty/start.d/http.ini e cambiato la porta in 9999 e poi eseguito le impostazioni predefinite: java -jar start.jar si avvia sulla porta 9999. Se è necessario eseguirlo da Maven, questo post potrebbe aiuto: [collegamento] (http://stackoverflow.com/questions/11652058/how-to-override-jetty-xml-with-jetty-port) –

1

Solo per completezza su pontile 7 è possibile utilizzare questo:

java -jar start.jar --module=http jetty.port=9080 
+0

Questa è una grande risposta. –

4

Ho cambiato il porta con successo, è possibile provare a modificare jetty.port nel file situato a $Jetty_home/start.d/http.ini.

3

È necessario modificare la porta http nel file start.ini perché sarà jetty-right.xml config.over.-right semplicemente commentare la riga in start.ini e mantenere la configurazione da jetty-http.xml. In [home molo] /start.ini

## HTTP port to listen on 
#jetty.port=8080 
6

ho fatto questo nella versione 9.x Jetty. Devi andare al file $ JETTY_HOME/start.ini e modificare questa impostazione jetty.port. Diciamo che si desidera eseguire molo al porto 9090: Si prega di modificare l'impostazione jetty.port a $ JETTY_HOME/start.ini da jetty.port = 8080 a jetty.port = 9090

Poi iniziamo molo utilizzando Opzione "java -jar start.jar". THEN jetty verrà eseguito alla porta 9090 rispetto alla porta 8080 predefinita. poi fare "curl -XGET -i" http://localhost:9090" Questo dovrebbe dare 200 di stato HTTP Ecco fatto

2

Aggiornamento:...

Sul Molo 9.x, jetty.port è stata deprecata ed è possibile utilizzare jetty.http.port invece, come illustrato di seguito:

$> cd $JETTY_HOME && java -jar start.jar -Djetty.http.port=8080 
2

Sul molo 9.2.3.v20140905 `s bisogno di scrivere in /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" 

ma questo cambiamento solo porta http. Per cambiare https porto molo 9.2 creare il file 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 

molo 9.3 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" 

o riga di comando parametri -Djetty.http.port=8080 -Djetty.ssl.port=443

Problemi correlati