Here's a step-by-step guide to installing GlassFish 5.1 and deploying a sample application on it:
1. Install Oracle Java 7/8:
- Update your package manager: `sudo apt-get update`
- Install required software properties: `sudo apt-get install python-software-properties`
- Add the Oracle Java repository: `sudo add-apt-repository ppa:webupd8team/java`
- Install Java 7/8: `sudo apt-get install oracle-java7-installer`
- Verify the Java version: `java -version`
2. Download and Install GlassFish 5.1:
- Get the GlassFish ZIP file: `sudo wget download.java.net/glassfish/5.1/release/glassfish-5.1.zip`
- Install unzip tool: `sudo apt-get install unzip`
- Create the /opt directory and unzip GlassFish to it: `sudo unzip glassfish-5.1.zip -d /opt`
- Add GlassFish bin directory to your PATH: Add `export PATH=/opt/glassfish4/bin:$PATH` to the end of ~/.profile
3. Start GlassFish Server:
- Start the GlassFish domain: `sudo asadmin start-domain`
4. Enable Secure Admin:
- Enable remote access to admin page: `sudo asadmin enable-secure-admin`
- Restart the domain to apply the changes: `sudo asadmin restart-domain`
5. Access GlassFish Admin Page:
- You can now access the admin page in your browser by visiting yourserverid:4848
6. Deploy a Sample Application:
- Download the sample application: `sudo wget https://glassfish.java.net/downloads/quickstart/hello.war`
- Deploy the WAR file: `sudo asadmin deploy /home/ee/glassfish/sample/hello.war`
- Visit the deployed application in your browser at yourserverid:8080/hello
7. Undeploy the Application:
- To remove the deployed application: `sudo asadmin undeploy hello`
8. Password File for Convenience:
- Create a password file named pwdfile with content: `AS_ADMIN_PASSWORD=your_admin_password`
- Use the password file when deploying or undeploying applications:
`asadmin --passwordfile pwdfile deploy /home/ee/glassfish/sample/hello.war`
That's it! Now you have GlassFish 5.1 installed, and you've deployed a sample application on it. Enjoy working with GlassFish for your Java EE applications!