23

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?

Mentiflectax
  • 13,367
  • 41
  • 152
  • 285

10 Answers10

34

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 :)

varna
  • 911
  • 8
  • 12
23

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!

Swanidhi
  • 1,849
  • 1
  • 16
  • 20
11

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

julg
  • 129
  • 1
  • 5
  • In my case, on Windows it was `SCComm` (an important task) that was using the 1099 port. So I could not just kill the task. Easiest solution was changing JMX port number, as this says. – Don Cheadle Aug 17 '16 at 16:04
9

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...")

Community
  • 1
  • 1
Andreas Lundgren
  • 10,546
  • 3
  • 18
  • 31
  • 1
    I fully favor this answer. Typically there is a java.exe process that I need to kill, which is the previous tomcat process still running. Killing this process resolves the problem. – Noremac Oct 22 '14 at 22:32
  • +1 for "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" which was exactly my case - thanks – Vic Torious Jan 16 '17 at 20:10
2

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!

uris
  • 5,563
  • 2
  • 23
  • 24
1

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

Srihari
  • 746
  • 1
  • 6
  • 21
  • When installing Tomcat I specifically entered port numbers, which were not present in the output of `netstat -A`. – Mentiflectax Sep 11 '13 at 12:14
  • How can I change the JMX port of Tomcat? – Mentiflectax Sep 11 '13 at 12:18
  • @DmitriPisarenko you can change the port in catalina-tasks.xml check this [documentation](http://tomcat.apache.org/tomcat-6.0-doc/monitoring.html#JMXAccessorOpenTask_-_JMX_open_connection_task) – Srihari Sep 11 '13 at 12:20
  • Some files mentioned there (e. g. *setenv.bat*) are not present in my installation, probably because I installed Tomcat as a Windows service. – Mentiflectax Sep 11 '13 at 12:43
  • @DmitriPisarenko - So you are on windows and not on MAC. Then please go to the folder where you installed tomcat and find the file named `tomcat6w.exe` and open the `java` tab. There you can find a text area named `java options`. In here add the following line `-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n`. Make sure to change `8000` to whatever port you want to debug on. You would have to restart tomcat using the GUI for the changes to work. – Srihari Sep 11 '13 at 12:53
  • @DmitriPisarenko Try separating the -X directives onto 2 different line in Java Options. If you are starting tomcat from within IDE, try to provide the same options in the JVM options as provided [here](http://www.jetbrains.com/idea/webhelp/run-debug-configuration-tomcat.html#d298586e381). – Srihari Sep 11 '13 at 13:27
0

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

user3642940
  • 371
  • 3
  • 4
0

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

Community
  • 1
  • 1
lk1234
  • 93
  • 1
  • 1
  • 6
0

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!

hal9000
  • 189
  • 1
  • 20
-2

Just close all other unnecessary servers while using InteliJ.

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