Introduction
This article will show how to list the applications available in the Glassfish Application Server. The term available means that it refers to the deployed applications on the Glassfish Application Server. Before the actual process for listing the deployed application in Glassfish Application Server, there are several steps for accomplishing the task. Those steps consist of several parts. The first one list to check whether the Glassfish Application Server is running. The second part is for the actual process which is listing the deployed applications in the Glassfish Application Server.
The First Part : Check the Glassfish Application Server
The first part will be a process for checking the Glassfish Application Server. The process exist within the seqences as follows :
First of all, check the process of the Glassfish Application Server. If Glassfish Application Server is listening or not for the incoming request. It is impossible to list the deployed application available if there is no running processes of the Glassfish Application Server. That process will listen to an incoming request. In this context, it is not every type of request but it is only for listening the incoming connection to the Glassfish Application Server. The process must listen to the incoming request on port 4848 which is representing the port number for accepting connection to the Glassfish Application Server. Just type the following command to check it :
netstat -tulpn | grep port_number
The following is the output of the above command pattern execution to check the port :
root@hostname ~# netstat -tulpn | grep 4848 tcp6 0 0 :::4848 :::* LISTEN 4465/java root@hostname ~#
Fortunately, the port for listening the incoming request to connect to the Glassfish Application Server is currently listening. In order to make sure that it is the right port which is belong to the right process, check the process further by executing the following command pattern :
ps aux | grep process_ID
Execute the above command pattern in the following output using the process ID shows in the above output :
root@hostname ~# ps aux | grep 4465 glassfi+ 4465 0.1 1.0 6281360 173492 pts/22 Sl Sep05 5:46 /usr/lib/jvm/java-8-openjdk-amd64/bin/java -cp /opt/glassfish4/glassfish/modules/glassfish.jar -XX:+UnlockDiagnosticVMOptions -XX:NewRatio=2 -XX:MaxPermSize=192m -Xmx512m -client -javaagent:/opt/glassfish4/glassfish/lib/monitor/flashlight-agent.jar -Djavax.net.ssl.trustStore=/opt/glassfish4/glassfish/domains/domain1/config/cacerts.jks -Dfelix.fileinstall.dir=/opt/glassfish4/glassfish/modules/autostart/ -Dorg.glassfish.additionalOSGiBundlesToStart=org.apache.felix.shell,org.apache.felix.gogo.runtime,org.apache.felix.gogo.shell,org.apache.felix.gogo.command,org.apache.felix.shell.remote,org.apache.felix.fileinstall -Dcom.sun.aas.installRoot=/opt/glassfish4/glassfish -Dfelix.fileinstall.poll=5000 -Djava.endorsed.dirs=/opt/glassfish4/glassfish/modules/endorsed:/opt/glassfish4/glassfish/lib/endorsed -Djava.security.policy=/opt/glassfish4/glassfish/domains/domain1/config/server.policy -Dosgi.shell.telnet.maxconn=1 -Dfelix.fileinstall.bundles.startTransient=true -Dcom.sun.enterprise.config.config_environment_factory_class=com.sun.enterprise.config.serverbeans.AppserverConfigEnvironmentFactory -Dfelix.fileinstall.log.level=2 -Djavax.net.ssl.keyStore=/opt/glassfish4/glassfish/domains/domain1/config/keystore.jks -Djava.security.auth.login.config=/opt/glassfish4/glassfish/domains/domain1/config/login.conf -Dfelix.fileinstall.disableConfigSave=false -Dfelix.fileinstall.bundles.new.start=true -Dcom.sun.aas.instanceRoot=/opt/glassfish4/glassfish/domains/domain1 -Dosgi.shell.telnet.port=6666 -Dgosh.args=--nointeractive -Dcom.sun.enterprise.security.httpsOutboundKeyAlias=s1as -Dosgi.shell.telnet.ip=127.0.0.1 -DANTLR_USE_DIRECT_CLASS_LOADING=true -Djava.awt.headless=true -Djava.ext.dirs=/usr/lib/jvm/java-8-openjdk-amd64/lib/ext:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext:/opt/glassfish4/glassfish/domains/domain1/lib/ext -Djdbc.drivers=org.apache.derby.jdbc.ClientDriver -Djava.library.path=/opt/glassfish4/glassfish/lib:/usr/java/packages/lib/amd64:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib com.sun.enterprise.glassfish.bootstrap.ASMain -upgrade false -domaindir /opt/glassfish4/glassfish/domains/domain1 -read-stdin true -asadmin-args --host,,,localhost,,,--port,,,4848,,,--secure=false,,,--terse=false,,,--echo=false,,,--interactive=true,,,start-domain,,,--verbose=false,,,--watchdog=false,,,--debug=false,,,--domaindir,,,/opt/glassfish4/glassfish/domains,,,domain1 -domainname domain1 -instancename server -type DAS -verbose false -asadmin-classpath /opt/glassfish4/glassfish/lib/client/appserver-cli.jar -debug false -asadmin-classname com.sun.enterprise.admin.cli.AdminMain root 23525 0.0 0.0 23960 1036 pts/35 S+ 09:29 0:00 grep 4465 root@hostname ~#
The Second Part : Connect to the Glassfish Application Server and List the Deployed Applications
This is the second part. It is also an important part of the article. Just connect to the Glassfish Application Server before proceeding to list the deployed applications. In order to be able to connect properly, read the article in this link with the title of ‘How to Connect to Glassfish Administration Console via Command Line’. The following is the command to connect to Glassfish Application Server :
asadmin
Depend on the location of the Glassfish Application Server, the pattern for the above command execution is vary. In this context, the location of the Glassfish Application Server is in ‘/opt/glassfish4/glassfish/bin’. Another practice for connecting and executing command with Glassfish Application Server is by switching to a user account specifically associated to manage the process of the Glassfish Application Server. So, switch to the ‘glassfish’ account first :
root@hostname ~# su - glassfish $
Continue on to execute the command ‘asadmin’ as follows :
$ /opt/glassfish4/glassfish/bin/asadmin Use "exit" to exit and "help" for online help. asadmin>
Finally, execute the command to list all deployed application exist by executing the following command in the Glassfish Administration Console in the command line interface :
asadmin> list-applications Nothing to list. No applications are deployed to this target server. Command list-applications executed successfully. $
As shown in the above output, there is not even a single deployed application running in the Glassfish Application Server. Actually, the above process for connecting to the Glassfish Administration Console and listing the deployed application is possible just using one single command execution. That command execution is available as follows :
root@hostname ~# runuser -u glassfish /opt/glassfish4/glassfish/bin/asadmin list-applications Nothing to list. No applications are deployed to this target server. Command list-applications executed successfully. root@hostname ~#