Install, Configure, and Deploy .war Application in Glassfish

Glassfish is a free, open source application server which implements the newest features in the Java EE 5 platform. The Java EE 5 platform includes the latest versions of technologies such as such as JavaServer Pages(JSP) 2.1, JavaServer Faces(JSF) 1.2, Servlet 2.5, Enterprise JavaBeans 3.0, Java API for Web Services(JAX-WS) 2.0, Java Architecture for XML Binding(JAXB) 2.0, Web Services Metadata for the Java Platform 1.0, and many other new technologies. You can use glassfish to replace apache web server or bea weblogic. The commercial version of this application server is Sun Java System Application Server.

Now what you need to do is download it, and don’t forget to install JDK, and set your JAVA_HOME to the jdk installation folder. In this test I’m going to use Windows base PC, so to set the JAVA_HOME, you need to go to:

Control Panel –> System –> Advanced –> Environment Variables –> Under User variable

Click new

In Variable Name put JAVA_HOME

In Variable Value put C:\Program Files\Java\jdk1.5.0_12

In case you put your JDK installation in this folder, then click OK button.

After you download glassfish, take the installer in this case a jar file. After that open your command prompt and type:

java -Xmx256m -jar filename.jar

It will prompt you some license agreement that you need to read first :D, then go to the installation directory:

cd glassfish

then you can type this to to initial setup

lib\ant\bin\ant -f setup.xml

It will took sometime, after the setup is finish then you already have your application server ready. Once you install using “ant -f setup.xml”, you start the server by starting the domain. A domain provides authentication and administration for the server instance that belongs to it. Starting the domain starts the server instance in the domain. A default domain called domain1 is created when you install GlassFish server. For administration tasks, the GlassFish server software provides these tools, which enable administrators to manage server instances:

The Admin Console, a browser-based graphical user interface (GUI)

The asadmin utility, a command-line tool

The default administration values are as follows:








master.password=changeit (only in setup-cluster.xml)

These values are used by the ant -f setup.xml or setup-cluster.xml command run at installation. If there is a port conflict during setup, please edit the setup.xml or setup-cluster.xml file with appropriate port values and rerun the ant command.

      In order you can access asadmin utility tools you need to add some variable to the environment variable:

      Control Panel –> System –> Advanced –> Environment Variables –> Under User variable

      Click new

      In Variable Name put PATH

      In Variable Value put C:\Program Files\glassfish\bin

      In case you put your Glassfish installation in this folder, then click OK button.

      Now you can check that by typing as and press tab in command prompt, if asadminsomething already there, then it already correct.

      Now you can test your application server by typing http://localhost:4848/ and see whether you can access your administration web, you will be prompted username and password, just type admin for username, and adminadmin for password, you can change this later.

      Now we can try to deploy application in this application server, first thing to do, is I’m trying to install . war application server, and i want this application server can be accessed by using empty or “/” context root. So it would be like you only need to type http://localhost:some-port/ to access your application.

      To do that we need to create another virtual server to be used by this virtual domain, you can do it by typing:

      asadmin create-virtual-server –hosts, servertest

      After creating the virtual server we need to make the listener for that virtual server, so it can be accessed by anyone, you can type this:

      asadmin create-http-listener –listeneraddress –listenerport 80 –defaultvs servertest listenertest

      In these configuration you can change the parameter to anything that you like, for example you can change the port address from 80 to 8080 or you only want this application server can be accessed from subnet, the  you can type to replace CMIIW.

      After this you need to go to the web admin, in the Resources tab you need to make a new connectionPools, in my case I want to make an Oracle 10g connection pool, before you do that, you need to download the driver. If you already have it, put it in glassfish\domains\domain1\lib\ext\folder

      In the Resources –> JDBC –> Connection Pools click new

      Inside there type the name as you wish

      choose the Resource Type, you can choose javax.sql.DataSource or anything that proper to your application

      choose your database vendor, in this case I will choose Oracle

      Then Click next

      In the additional properties put the value in this properties: user, password and URL

      user and password would be self explanatory, while URL will be like jdbc:oracle:thin:@database-ip:1521:SID

      To test it you can try to ping. After you create the connection pool you can create JDBC resource that is going to be used by your application. Your connection pool can be used many time, but not with your JDBC resources CMIIW. The step to make that:

      In the Resources –> JDBC –> JDBC Resources click new

      In the JNDI name, you have to input the name the same with the one that you specify in your application settings

      In the pool (Connection Pool) name you have to choose with the one that make previously

      Then click OK

      Then you have just finish making a connection to the database. Now you need to deploy the application (file with .war), you need to type:

      asadmin deployd –virtualservers servertest –contextroot “/” –name application war-name.war

      and if your application have config file you need to put that in glassfish\domains\domain1\lib\classes\ Well that’s all what you can do if you want to deploy application using glassfish. For your information I’m new in this stuff so I think I might make some mistake in this configuration, so let me know if you find some 😀


      14 thoughts on “Install, Configure, and Deploy .war Application in Glassfish

      1. hi,nice tutorial ,thanks,
        how to add user variable in glassfish,in an application the certain configuration ,eg: we are using opensso so there is goto url which need to change according to the port the client location specifies ,how to add the port in glassfish and acess the same in our application .please give me good solution

      2. Dear Sir,

        I am new to J2EE.

        I have developed a J2EE 5 application using JDK1.6.0, MySql5.1, Glassfish2.1, Netbeans6.5.1 on Windows Machine.

        Please advise me the steps to deploy on Glassfish2.1on CentOS6.0 having JDK1.6.0, MySql5.1.

        Thanks and Regards.

        Arumugam AV

      Leave a Reply

      Fill in your details below or click an icon to log in: Logo

      You are commenting using your account. Log Out /  Change )

      Google+ photo

      You are commenting using your Google+ account. Log Out /  Change )

      Twitter picture

      You are commenting using your Twitter account. Log Out /  Change )

      Facebook photo

      You are commenting using your Facebook account. Log Out /  Change )

      Connecting to %s