False java.net.BindException: 地址已在 Jetty 上使用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28497308/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 13:41:46  来源:igfitidea点击:

False java.net.BindException: Address already in use on Jetty

javamavencontinuous-integrationjettyrhel

提问by orshachar

On my CI server I have a test that needs to start Jetty server.
The test goes like this:

在我的 CI 服务器上,我有一个需要启动 Jetty 服务器的测试。
测试是这样的:

  1. Generate random port (using java rand in legit TCP port range).
  2. Validate using Linux's fuserto check that port in not in use
  3. Run the tests
  1. 生成随机端口(在合法的 TCP 端口范围内使用 java rand)。
  2. 使用 Linux 验证fuser以检查未使用的端口
  3. 运行测试

Occasionally, even after validating the port is free, I get the exception:

有时,即使在验证端口是免费的后,我也会收到异常:



WARN:oejuc.AbstractLifeCycle:FAILED [email protected]:49277 FAILED: java.net.BindException: Address already in use
java.net.BindException: Address already in use
    at sun.nio.ch.Net.bind0(Native Method)
    at sun.nio.ch.Net.bind(Net.java:444)
    at sun.nio.ch.Net.bind(Net.java:436)
    at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:214)
    at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
    at org.eclipse.jetty.server.nio.SelectChannelConnector.open(SelectChannelConnector.java:172)
    at org.eclipse.jetty.server.AbstractConnector.doStart(AbstractConnector.java:300)
    at org.eclipse.jetty.server.nio.SelectChannelConnector.doStart(SelectChannelConnector.java:249)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
    at org.eclipse.jetty.server.Server.doStart(Server.java:272)
    at org.mortbay.jetty.plugin.JettyServer.doStart(JettyServer.java:65)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
    at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:511)
    at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:364)
    at org.mortbay.jetty.plugin.JettyRunWarMojo.execute(JettyRunWarMojo.java:71)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)


The test that runs on:

运行的测试:

  • RHEL 6.3 host
  • Maven 3.0.4
  • jetty-maven-plugin:7.5.4
  • Java 1.7.51
  • RHEL 6.3 主机
  • Maven 3.0.4
  • 码头行家插件:7.5.4
  • Java 1.7.51

What can possibly be the reason?

可能是什么原因?

Thanks!

谢谢!

回答by Joakim Erdfelt

There is a process on port 49277already when Jetty attempts to startup.

49277当 Jetty 尝试启动时,端口上已经有一个进程。

No way around that.

没办法。

You can ask Linux what's listening, and see what process is using that port.

您可以询问 Linux 正在侦听什么,并查看正在使用该端口的进程。

$ netstat -tlnp

However, if all you want is a random port that Jetty can startup and listen on, just set the port that Jetty should use to 0, and that will tell TCP to randomly assign an available port when binding for listening.

但是,如果您只想要一个 Jetty 可以启动和侦听的随机端口,只需设置 Jetty 应该使用的端口,0这将告诉TCP 在绑定侦听时随机分配一个可用端口

Your task then, is to figure out what port Jetty is listening on after startup.

然后,您的任务是找出 Jetty 在启动后侦听的端口。

回答by vaibhav singh

You might be using tomcat on 8080 port please stop the tomcat server and run jetty from maven again.

您可能正在 8080 端口上使用 tomcat,请停止 tomcat 服务器并再次从 maven 运行 jetty。