23

I'm using Intellij, attempting to deploy a Tomcat application, but whenever I try to run it, I get the following error:

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:

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?

5
  • It means that something's still running on that port. You could try running on a different port? Commented Jun 6, 2014 at 19:05
  • Isn't 1098 the port for RMI? Maybe IntelliJ is using it. Just take another port. Commented Jun 6, 2014 at 19:07
  • As per @ThomasUhrig -- try port 8080, and see if you still have a problem. Commented Jun 6, 2014 at 19:11
  • Port that you are using is in use. Try using some other port. Commented Jun 6, 2014 at 19:14
  • @EngineerDollery I am using port 8080, but the JMX port keeps defaulting to 1098 which is what is throwing the error. And I can't remove it, because it needs a port. Commented Jun 6, 2014 at 19:27

6 Answers 6

24

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.

One way to fix this is to define your CATALINA_OPTS environment variable.

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.

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:

export CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8999"

Credit: https://bowerstudios.com/node/636

Sign up to request clarification or add additional context in comments.

Comments

2

enter image description hereClick on the skull icon after stopping server to kill all associated processes. This should help in resolving the port issue.

2 Comments

what is the prerequisite for seeing that skull button? On my Spring Boot project there is no such thing within that toolbar
either your server is still running or you terminated and termination did not complete.
0

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.

Comments

0

I found this questions many times in Tomcat.

错误: 代理抛出异常 : java.rmi.server.ExportException: Port already in use: 912 3; nested exception is: 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

Comments

0

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

Comments

0

I have faced this problem while starting the SymmetricsDS service. Here is my solution for Linux and it works later.

top | grep java
kill -9 javaPID

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.