Search code examples
javanetbeansglassfishservernetbeans-8

How to deploy a Web Application on specific port of glassfish using Netbeans IDE?


This is noob question but still...

My localhost port 8181 is working but when I run my web application via Netbeans IDE, the default port is 8080. How can I change the default port to 8181?


Solution

  • It looks like NetBeans 8 reads the default port from http-listener-1 in your domain.xml.

    To change it, you have to assign a different port to http-listener-2, because this one uses port 8181 by default.

    To do that you have different options:

    A)

    You can open the Glassfish Admin UI via http://localhost:4848.

    Navigate to server-config -> Network Config -> Network Listeners -> http-listener-2 and change the port to something like 8282 (8080 is currently in use by http-listener-1).

    Now do the same for http-listener-1 and change the port to 8181.

    B)

    You can also change it manually directly in the domain.xml, shutdown Glassfish before you start.

    Open /glassfish_installation/glassfish/domains/domain1/config/domain.xml with a text-editor and search for 8080. There should be something like:

     <network-listener port="8080" protocol="http-listener-1" transport="tcp" name="http-listener-1" thread-pool="http-thread-pool"></network-listener>
     <network-listener port="8181" protocol="http-listener-2" transport="tcp" name="http-listener-2" thread-pool="http-thread-pool"></network-listener>
    

    Change that to:

     <network-listener port="8181" protocol="http-listener-1" transport="tcp" name="http-listener-1" thread-pool="http-thread-pool"></network-listener>
     <network-listener port="8080" protocol="http-listener-2" transport="tcp" name="http-listener-2" thread-pool="http-thread-pool"></network-listener>
    

    C)

    You can use asadmin:

    asadmin set configs.config.server-config.network-config.network-listeners.network-listener.http-listener-2.port=8282
    
    asadmin set configs.config.server-config.network-config.network-listeners.network-listener.http-listener-1.port=8181
    

    (This works for Glassfish v4, for other versions you may have to adjust the "config path".)

    The final step of these solutions is to restart Netbeans and you should be done.

    See also: