23
votes

I need to debug a web application for Tomcat6 in IntelliJ IDEA.

When I try to run my web application, I get two errors:

  1. Address localhost:1099 is already in use
  2. Unable to open debugger port: java.net.SocketException

Launching the Apache Tomcat 6 service manually works fine.

What should I do in order to be able to debug web applications in Apache Tomcat 6 from Intellij IDEA?

10

10 Answers

34
votes

Following the below steps work:-

  1. Open command prompt and type the command netstat -ano
  2. You will see a list of active TCP connections with PID as the last column
  3. See the second column listing the local addresses and find the one using port 1099 from it and you'll get its PID
  4. Now open your Task Manager, click the Process tab and get the PID column to display [either by right clicking on the heading row and selecting PID OR click View, and then click Select Columns and select PID.]
  5. Now find the PID we got from Step3 and end the process.

Now you are good to go :)

24
votes

I face this issue all the time. Here's how to fix it

LINUX

Open a terminal instance.

fuser 1099/tcp

This should return you a process ID.

1099/tcp:            31596

where 31596 is the process ID. Now you can either use the process ID to kill it or just bash the following -

fuser -k 1099/tcp

WINDOWS

Open a command prompt instance.

netstat -aon | find "1099"

This will return you an instance of the process.

output:

TCP    0.0.0.0:1099       0.0.0.0:0       LISTENING       15776

Here 15776 is the process ID. To kill this, enter -

taskkill /F /PID 15776

Cheers!

11
votes

You can change the JMX port (1099 per default) in the Run/Debug Configuration dialog. Just try a different port number (i.e. 9099).

9
votes

If you had the web application up and running before, there may be an old debug server that did not close down properly running in the background. See this post about how to find what process that uses port 1099. If it proves to be a java process, kill it.

How can you find out which process is listening on a port on Windows?

(If you use the GUI sw suggested in the link above, you may kill the process(es) by marking all java processes that uses port 1099, right click and press "End Process...")

2
votes

As said before, there's an old debug server running in the background.

My solution was to close the Java process that was left open from the Windows Task Manager.

Please verify that you can close this process before doing so!

1
votes

Change your http port to 8080(default for tomcat) and debug port to something that is not being used currently by any processes. You can use anything that is upwards of 1024, but since you are getting an error on 1099, try something that is greater that 6000.

Debugger setting can be found here

0
votes

There might be other program or server running at the background. First close other server running in the background and then restart your server.

0
votes

I found this answer helpful:

How can you find out which process is listening on a port on Windows?

I opened the resource monitor and looked for what was using the ports. Then opened task manager and ended those processes

0
votes

What worked for me was. I assumed I would need to have the "Apache Tomcat" service running under "Services" [Windows + R >> services.msc]

I went and stopped the Tomcat service here. Then I came to my Java application and ran it in Intellij, which allowed me to run it.

Hope this helps!

-2
votes

Just close all other unnecessary servers while using InteliJ.

I stopped my WAMP in order to remove this error "Port is already in use".