Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 更改Jetty默认端口_Java_Maven_Jetty_Maven Jetty Plugin - Fatal编程技术网

Java 更改Jetty默认端口

Java 更改Jetty默认端口,java,maven,jetty,maven-jetty-plugin,Java,Maven,Jetty,Maven Jetty Plugin,Jetty的默认端口是8080,但我想将默认端口更改为其他端口(9999) 我读了一些教程,他们说几乎所有的配置信息默认都保存在文件jetty.xml中,该文件位于$jetty\u HOME/etc/下。然后,将属性jetty.port更改为9999。但是,当我打开该文件时,在jetty.xml中找不到jetty.port属性。我目前正在使用Jetty-9.2.1,端口为8080 我在jetty-http.xml文件下找到了jetty.port属性。即使我在jetty-http.xml文件中将端

Jetty的默认端口是8080,但我想将默认端口更改为其他端口(9999)

我读了一些教程,他们说几乎所有的配置信息默认都保存在文件
jetty.xml
中,该文件位于
$jetty\u HOME/etc/
下。然后,将属性
jetty.port
更改为9999。但是,当我打开该文件时,在
jetty.xml
中找不到jetty.port属性。我目前正在使用Jetty-9.2.1,端口为8080

我在jetty-http.xml文件下找到了jetty.port属性。即使我在jetty-http.xml文件中将端口更改为8090,jetty仍然在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>
<?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>

如果在从命令行启动端口时设置端口,它是否工作,如下所示:

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

为了确保jetty 7的完整性,您可以使用:

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

我成功更改了端口,您可以尝试编辑位于
$jetty_home/start.d/http.ini的文件中的
jetty.port
,您需要更改start.ini文件中的http端口,因为它将覆盖右jetty-http.xml配置。或者只需注释start.ini中的行,并保留jetty-http.xml中的配置。 在[jetty home]/start.ini中

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

我在Jetty 9.x版本中这样做了。 您需要转到
$JETTY\u HOME/start.ini
文件并编辑此设置JETTY.port

假设您希望在9090端口运行jetty: 请从更改
$jetty\u HOME/start.ini中的
jetty.port
设置

jetty.port=8080

然后使用
java-jarstart.jar
选项启动jetty。 然后,jetty将在9090端口运行,而不是默认的8080端口。 然后执行
curl-i-XGET“http://localhost:9090“
。这将为您提供200个http状态

就这样。

更新:

在Jetty 9.x上,
Jetty.port
已被弃用,您可以改用
Jetty.http.port
,如下所示:

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

在jetty 9.2.3.v20140905上,需要写入
/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"
但这只改变了http端口。要更改jetty 9.2中的https端口,请创建ini文件
$jetty\u 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
码头位于
/etc/default/jetty

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

或者命令行参数
-Djetty.http.port=8080-Djetty.ssl.port=443

如果使用的是eclipse,则需要设置运行配置。在eclipse中安装jetty时,jetty的默认端口为8080

因此,您需要将其更改为XML文件。如果问题仍然存在,则需要在eclipse运行配置中对其进行更改


我希望它能起作用,就像它对我起作用一样。

对于IntelliJ,这可以类似于Magnus Lassi的命令行回答

运行-->编辑配置-->添加“-Djetty.port=XXXX”,例如:


对于SSL端口,您可以传递参数:

-Dssl.port=8445

它对我有效。

这不会更改默认端口。在运行这一行之后,当我运行
java-jar start.jar
时,Jetty仍然在端口8080下运行。我正在寻找一种永久更改默认端口的方法。@wag0325我只是想知道,为了解决这个问题,它是否会有所不同。更新jetty/start.d/http.ini并将端口更改为9999,然后运行默认设置:java-jar start.jar,它将在端口9999上启动。如果您需要从maven运行它,那么这篇文章可能会有所帮助:文档中说
mvn-Djetty.http.port=8181 jetty:run
但是你的建议对我有用。可能是因为我有这样定义的上下文路径`org.mortbay.jetty jetty maven plugin 8.1.14.v20131031/http`
mvn-Djetty.port=8181 jetty:run
帮助您在端口818181btw上启动jetty,如果您应该使用spring boot并在下面使用jetty的话
--server.port=8090
在jetty-http.xml中更改jetty.port设置对我很有效。也许您有另一个使用端口9999的应用程序?这是一个很好的答案。
# JETTY_ARGS
# The default arguments to pass to jetty.
# For example
JETTY_ARGS="jetty.http.port=8080 jetty.ssl.port=443"
jetty:run-war -Djetty.port=9999
-Dssl.port=8445