views:

212

answers:

3

Hi All, I use eclipse to develop a web based java application. My normal course of business is grab the next task tracking ticket. If there is a problem that needs to correcting, I run the application locally, which loads of a Jetty webserver, and binds to port 8080. After verifying the problem, I fix the problem, rebuild, and the re-run the application. The problem is, I far too often forget to close the jetty server before re-running. This generates the Java bind error:

WARNING: failed [email protected]:8080: java.net.BindException: Address already in use: JVM_Bind

I work in Windows, and was looking to see if there is command I could run to un-bind the port, but couldn't find an answer there. Does anyone here have a good idea of how to fix my problem, other than remember to shut down the old jetty instance before starting a new one?

Thanks, Jay

A: 

You sortof answered your own question there... since you can't run two applications on the same port you'll need to remember to shut down the old one before starting a new one.

You mention the application starts a Jetty instance, could that launching application check if it's already running before doing so? I guess I'm not quite on the same page as you...

However, there are some nifty ways out there to "hot deploy" your changes -- once you have the appserver running you can make changes to JSP files or Java classes and it will automatically deploy those changes.

Are you using some integration like run-jetty-run? If not, you might want to give that a try.

MyEclipse also comes to mind, though I'm not a huge fan of it, some people really like it.

But for the most part, just remember to stop and restart.

dustmachine
good point, I use JRebel for hot re-compile
Jay
A: 
  1. Use netstat -ap | grep 8080 to find which process is using that port. (What, you don't have a suitable grep installed on Windows? Everyone should!)
  2. Use -Djetty.port=<port number> to change the default port number used by Jetty.
matt b
What grep installation would you recommend? Free is preffered.
Jay
@Jay, Cygwin and msysgit both include grep's, both work fine. http://www.cygwin.com/ http://code.google.com/p/msysgit/
matt b
A: 

To unbind the port cleanly, you typically need to stop the process that is holding it open (otherwise, the process would probably die with strange communication errors anyway).

You could right a short batch file to detect if the port is in use and kill the Jetty process. Assuming you have Sysinternal's pskill.exe available in your path (e.g. under C:\Windows), here's an example that will kill the process which is holding port 8080 open:

FOR /F "skip=4 tokens=2,5" %%G IN ('netstat -ano') DO (
  IF "%%G"=="127.0.0.1:8080" pskill %%H
)
ewall