Installing and Setting Up Glassfish 2

To install and setup a domain in the Glassfish 2 application server. We can then use this Glassfish server for various java tutorials such as web-services, EJBs and JMS. This covers basic setup and configuration of Glassfish 2. Leave any questions or problems as comments and I will endeavour to answer them.

We assume that the jdk 1.5.0 or compatible version and Ant are already installed.

Versions used in this example
Software ComponentImage
Glassfish 2glassfish-installer-v2.1-b60e-windows.jar
Ant 1.7
JDK 1.5.0N/A
Links to these files can be found here

  1. Download the image/binary and save it to the directory where you wish to install glassfish. Example C:\Program Files\.
  2. `
  3. Now open a command prompt and cd into the directory where you saved the file.
  4. `
  5. Run java -jar to unpack the file. This will create a directory called glassfish.

    C:\Program Files>java -jar glassfish-installer-v2.1-b60e-windows.jar
    This will popup a window with the license agreement. Scroll to the end and press Agree. You should see your prompt fill up with files being unpacked.
  6. `
  7. Now cd into the glassfish directory that the previous command created.
  8. `
  9. Run ant on the setup.xml file. I don't have ant in my path so I'm specifying the full path to my ant executable.

    C:\Program Files\glassfish>D:\downloads\apache-ant-1.7.1\bin\ant -f setup.xml
  10. `
  11. Create a directory called domains under the glassfish directory.
  12. `
  13. Now cd into the glassfish\asadmin\bin directory,
  14. `
  15. Run the asadmin create-domain command to create a domain for our applications. I have chosen port 8082 because on conflichs with apache's web-server and tomcat. You can put in whatever you like. This will create a domain1 directory under the domains directory.

    ...glassfish\bin>asadmin create-domain --adminuser admin --adminport 4848 --instanceport 8082 domain1
    Remember the passwords you typed for admin and master password. The name of this domain will be domain1.
  16. Cd into the domain1\bin directory and run startserver.bat. For admin username type admin and type the passwords you entered when you created the domain.
  17. `
  18. Check the logfiles at domain1\logs to make sure everything looks ok.
  19. `
  20. Open a browser and go to You should see a welcome page.
  21. `
  22. In the browser type and login using admin and the password you created. You are now done.

Back to the tutorial trail | Home.


Nguyen Duc said...

Step7. It should be "glassfish\bin\asadmin"

After stẹp5, setup.xml file created 'domain1' in 'domains' folder. I deleted it and re-created 'domain1' as you say. Is it ok?

Anonymous said...

i encounter errors in my server logs. what should i do?

Naviya Nair said...

Very interesting and good Explanation
ASP NET Training
ASP NET Training
ASP NET Online Training
C-Sharp Training
Dot Net Training in Chennai
Online .Net Training

MVC Training
WCF Training
Web-API Training
LINQ Training
Entity Framework

Dot Net Interview Questions