“java.net.BindException: Address already in use”错误的解决方法?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24088924/
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
Solution to "java.net.BindException: Address already in use" error?
提问by carbon_ghost
I'm using Intellij, attempting to deploy a Tomcat application, but whenever I try to run it, I get the following error:
我正在使用 Intellij,试图部署一个 Tomcat 应用程序,但是每当我尝试运行它时,我都会收到以下错误:
Error: Exception thrown by the agent : java.rmi.server.ExportException: Port already in use: 1098; nested exception is:
java.net.BindException: Address already in use
Now I've manually looked for the process happening at that port via:
现在我已经通过以下方式手动查找在该端口发生的过程:
lsof -i:1098
And I found the java process and killed it too:
我找到了java进程并杀死了它:
ps aux | grep java
kill -9 20386
And that worked, but I have to do this EVERYTIME I open Intellij. If I want to rerun the server without exiting Intellij, I can't, because I'll get this error. Does anyone know of a permanent fix for this and not just manually killing it everytime?
那行得通,但我每次打开 Intellij 时都必须这样做。如果我想在不退出 Intellij 的情况下重新运行服务器,我不能,因为我会收到此错误。有没有人知道对此有永久修复,而不仅仅是每次都手动杀死它?
采纳答案by digicyc
This is due to JMX monitoring the Tomcat instance. Tomcat will be running on port 9999 so when JMX wants to start to check for the shutdown it can't bind to this port.
这是由于 JMX 监视 Tomcat 实例。Tomcat 将在端口 9999 上运行,因此当 JMX 想要开始检查关闭时,它无法绑定到此端口。
One way to fix this is to define your CATALINA_OPTS environment variable.
解决此问题的一种方法是定义您的 CATALINA_OPTS 环境变量。
Setting these properties in JAVA_OPTS tries to start a jmx server when you start tomcat AND when you shutdown tomcat. Hence the port already in use exception. You need to set these properties for CATALINA_OPTS instead of JAVA_OPTS. This will only run when you start tomcat.
在 JAVA_OPTS 中设置这些属性会尝试在您启动 tomcat 和关闭 tomcat 时启动 jmx 服务器。因此端口已被使用异常。您需要为 CATALINA_OPTS 而不是 JAVA_OPTS 设置这些属性。这只会在您启动 tomcat 时运行。
CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8999" CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"
CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8999" CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management. jmxremote.authenticate=false"
What fixes it for me is in $HOME/.bashrc I add this export:
对我来说修复它的是在 $HOME/.bashrc 我添加了这个导出:
export CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8999"
export CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8999"
回答by Gayathri
Click on the skull icon after stopping server to kill all associated processes. This should help in resolving the port issue.
停止服务器后单击骷髅图标以终止所有相关进程。这应该有助于解决端口问题。
回答by Amritpal Singh
I ran into this problem, I didnot kill my previous running app on the same port. I just killed it using kill -9 PID and I was fine.
我遇到了这个问题,我没有在同一个端口上杀死我以前运行的应用程序。我刚刚使用 kill -9 PID 杀死了它,我很好。
回答by Lucas
I found this questions many times in Tomcat.
我在Tomcat中多次发现这个问题。
错误: 代理抛出异常 : java.rmi.server.ExportException: Port already in use: 912 3; nested exception is: java.net.BindException: Address already in use
错误: 代理抛出异常: java.rmi.server.ExportException: Port already in use: 912 3; 嵌套异常是:java.net.BindException: Address already in use
In tomcat [cc@Cdf bin]$ vim catalina.sh change the 9123 to a inactive number ,for example 8998 . and then , [cc@Cdf bin]$ ./start.sh;tailf ../logs/catalina.out
在 tomcat [cc@Cdf bin]$ vim catalina.sh 中,将 9123 更改为非活动数字,例如 8998 。然后, [cc@Cdf bin]$ ./start.sh;tailf ../logs/catalina.out
回答by Mahesh Shivaji Mane.
Right Click on the project --> Run As --> Run Configurations ---> On left hand side select project under Spring Boot App --> change the JMX Port and try
右键单击项目 --> 运行方式 --> 运行配置 ---> 在左侧选择 Spring Boot App 下的项目 --> 更改 JMX 端口并尝试