GlassFish: How to deploy a war file

Before trying this out make sure you have installed GlassFish in your machine. Installation is just easy as downloading the zip archive from here and unzipping it to a desired location.

Creating a new domain

Open up a terminal, change directory to the GlassFish installation directory and run following.
 
 
 

bin/asadmin

Screenshot from 2012-08-20 21-43-15

This will enable you to use asadmin tool. Now execute the following command to create a new domain. after running this command you will probably have to give admin password and master password.

create-domain --adminport 5000 --profile developer --user admin domain2

Screenshot from 2012-08-20 21-49-32

Now open up another terminal and change directory to [glassfish-installation]/domains/ and you will see the newly created domain2 has appeared there.

Screenshot from 2012-08-20 21-50-58

Open up a browser and go to http://localhost:5000/. This will bring you the GlassFish GUI admin console. This is one place you can deploy your war file. But in this post I’m not much focusing on it, instead I will show you how to do this using the command line. But GUI lovers, for any consolation I have put some screenshots which you can follow if you prefer the GUI way.

Screenshot from 2012-08-20 22-47-03Screenshot from 2012-08-20 22-47-24

Screenshot from 2012-08-20 23-26-53

Screenshot from 2012-08-20 23-27-17

Screenshot from 2012-08-20 23-27-46

In case you want to delete a domain use the following command.

delete-domain domain2

Screenshot from 2012-08-21 04-02-33

Starting the domain

To start domain2 run following command.

start-domain domain2

Screenshot from 2012-08-20 21-53-14

Deploying a war file

Use the following command to deploy your war file.

deploy --port 5000 --host localhost /home/pavithra/workspace/NewDemoService/WebServicesJaxWs/NewDemoService.war

Screenshot from 2012-08-20 22-00-12

After deploying the war file I can access the WSDL file I want to access using the URL http://localhost:8080/NewDemoService/NewDemoService?WSDL

Screenshot from 2012-08-20 23-25-13

To change default 8080 (HTTP) port which specifies where the web application context roots are available for a Web browser to connect to, you can use the –instanceport parameter when creating the domain. See the following command.

create-domain --adminport 5000 --profile developer --user admin --instanceport 9000 domain2

Screenshot from 2012-08-21 04-05-50

Screenshot from 2012-08-21 04-17-15
Undeploying a war file

To undeploy NewDemoService.war file you need to use the following command. Note that here you don’t have to use the full name but literal “NewDemoService”.

undeploy --port 5000 --host localhost NewDemoService

Screenshot from 2012-08-20 23-39-27

Stopping a domain

To stop the domain “domain2″ use the following command.

stop-domain domain2

Screenshot from 2012-08-20 23-45-11

After this if you try to deploy to this particular domain, it will complain.

Auto Deploy

To perform auto deploy, copy NewDemoService.war file in to [glassfish-installation-directory]/domains/domain2/autodeploy directory. If autodeploy succeeds, you will see NewDemoService.war_deployed has created. This will deploy your war file automatically.

Screenshot from 2012-08-21 04-48-54

Screenshot from 2012-08-21 04-51-04
 
Reference: How to deploy a war file using GlassFish from our JCG partner Pavithra Siriwardena at the EVIAC blog.

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

JPA Mini Book

Learn how to leverage the power of JPA in order to create robust and flexible Java applications. With this Mini Book, you will get introduced to JPA and smoothly transition to more advanced concepts.

JVM Troubleshooting Guide

The Java virtual machine is really the foundation of any Java EE platform. Learn how to master it with this advanced guide!

Given email address is already subscribed, thank you!
Oops. Something went wrong. Please try again later.
Please provide a valid email address.
Thank you, your sign-up request was successful! Please check your e-mail inbox.
Please complete the CAPTCHA.
Please fill in the required fields.

Leave a Reply


4 × = twenty



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy | Contact
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
Do you want to know how to develop your skillset and become a ...
Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

Get ready to Rock!
You can download the complementary eBooks using the links below:
Close