This document gives a (rough and incomplete) overview of GlassFish, a Java EE application server. This document may serve as an introduction to application servers in Java EE.
Java EE defines a set of specifications, known as Java Specification Requests (JSR). Application servers have to implement (parts of) these standards in order to be compliant with (a subset of) Java EE. An important standard among those is the Servlet API, or JSR 369.
A Java EE application server is a piece of software that ease the development of web applications, by providing services to the Java web developer. Your application server provides containers in which you, the web developer, embed your code. The container calls your code whenever adequate. For example, we use the web container in the Servlets document.
Examples of Java EE compliant application servers: GlassFish (Oracle, open source, reference implementation of Java EE), WildFly (Red Hat / JBoss, open source), WebSphere AS (IBM)…
-
Download and install a local copy of GlassFish (see Tools).
-
Note in particular the important
…/glassfish/binand…/glassfish/domains/domain1/autodeploydirectories. -
The server is commanded thanks to the
asadmincommand (in thebinsubfolder). This command is to be run in a terminal. -
Start the server with
asadmin start-domain: this starts domain1, the default configured domain. -
Stop the server by typing
asadminthenstop-domain. (Equivalently:asadmin stop-domain.)
Any compliant Java EE server comes with an embedded SQL database management system, that will be used as a default for deployed applications if none other is configured.
-
Start the database with
asadmin start-database. Guess how to stop it?
Supplementary to the somewhat austere asadmin command line utility, it is possible to configure many aspects of the server using its graphical administration console.
When the server starts, it tells you (on the terminal) its admin port (usually 4848); and the place it logs to (usually …/glassfish/domains/domain1/logs/server.log).
Browse to http://localhost:4848/ to open the Administration console. Open Configurations / server-config / Network Config / Network Listeners / http-listener-1. Look at the address and port the server is listening on for normal operation (usually 8080).
Browse to http://localhost:8080/ and check that you see the “Your server is now running” page. Browse to your external IP address on the port 8080 (for example, http://192.168.0.1:8080) and check that you see the same thing. That’s because http-listener-1 is listening to the address 0.0.0.0, meaning every address.
For increased security, in the Administration Console, change the address field and indicate there localhost. Click Save. Check that your server is no more reachable (on port 8080) from your external IP address, but is still reachable from the localhost address.
Run asadmin set server-config.network-config.network-listeners.network-listener.admin-listener.address=localhost and asadmin set server-config.network-config.network-listeners.network-listener.http-listener-2.enabled=false to finish (minimally) securing your server. Guess what these commands do and check your intuition. (Changes to the admin-listener port only take effect after a reboot of the server, though changes to the normal http listeners are immediately effective.)
Open the server log file in a text editor and check that you see the logs related to what you just did.
The autodeploy directory is used to deploy your application, once it is packaged appropriately (e.g. as a WAR file). Simply drop the file there. GlassFish will then create a file in the same folder to tell you whether the application was deployed successfully. (Check the Servlets document to learn how to create an adequate file.)
When you can’t reach your servlet, check whether GlassFish sees it. (Tested under GlassFish 4.1.2.)
-
Start your domain
-
Look in the Administration console, Applications (or run
asadmin list-applications) ⇒ check that your application appears, otherwise, it is not deployed correctly -
Click on your application to see the
Modules and Componentstable (or runasadmin list-sub-components<app-name>) ⇒ check that your servlet class appears as a component of type Servlet.
If your application deploys but your servlet isn’t seen, you may have forgotten an annotation. Do check the server log, it probably contains useful information.
Run /usr/local/bin/asadmin create-jvm-options -ea (then restart the server) to enable Java assertions. (This can also be done through the Administration console, Configurations, JVM Settings, JVM Options.)