Tuesday 11 September 2012

Change Glassfish default server port number once domain has been created

Today I encounter a problem when trying to start the Glassfish server in the Eclipse.

Here is the error:



















It turns out the port 8080 is occupied on my machine while Glassfish's default server port number happens to be 8080 as well.

I used command netstat -o to find out which process is using port 8080.
















The result doesn't make much sense to me. What does PID being 0 mean? I have no idea. Since this is a company computer, someone may have installed some weird software before. Killing that process and freeing port 8080 doesn't appear to be the best solution. So the question now comes to how to change the Glassfish's default server port number to something else.

When I first try to install Glassfish 3.1, I download an exe version. The exe installer does allow me to specify my own server port number. However, Eclipse doesn't like it. Eclipse only accepts the zip version.

In the process of creating a new Glassfish server instance in Eclipse, Eclipse doesn't provide much setting to configure.  Other than setting the path for the domain, everything else seems to be set as the default value.

I open the config folder under the domain just created. Suppose your root folder of Glassfish is c:\glassfish3, then the config folder is likely to be at c:\glassfish3\glassfish\domains\domain1.

I open the file named domain.xml because it looks likely to have the domain information, including the port number.

I search 8080, and there is one match.










I change 8080 to 9090 and restart the server. It still pops up the same error message.

I then remove the server instance from Eclipse and create a new server instance again.

Then it works like a charm.