JavaEE Simple Web App with GlassFish
This is a guide to starting a basic web project for JavaEE. It’s assumed that JavaEE is set up and ready to go.
Download Eclipse for JavaEE. It’s here: https://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/lunasr2
Extract the contents and open Eclipse
tar -xvf eclipse-jee*
rm eclipse-jee*
./eclipse/eclipse
Install the GlassFish plugin
Help > Install New Software
In the ‘Work With’ field, set:
http://download.oracle.com/otn_software/oepe/12.1.3.6/luna/repository
Let it load
Select
Tools > GlassFish tools
Tools > Oracle Java EE tools
Press Next / Finish / Agree etc
Start a new project
File > New > Dynamic Web Project
Select the Target Runtime
to be GlassFish. If GlassFish is not listed, you need to install it by pressing the New Runtime
button and then Download additional server adapters
link and selecting GlassFish
. Press Next
. You need to specify a server root as an absolute path which for me is /home/me/glassfish4/glassfish
.
Click through all the prompts until you’re finished creating your project.
Make a ‘page’
File > New > Servlet
Fill in the Java package
field and a Class name
field. Click Finish
.
Add some content to the doGet
method.
protected void doGet(...) {
PrintWriter out = response.getWriter();
out.print("Hello World");
}
Run the project
Run > Run As > Run on Server
This will automatically open your browser at the root of your project. You will need to change the url to the path as specified in your class (it’s prepopulated). The url is structured as http://localhost:8080/ProjectName/ClassName
, which in my case is http://localhost:8080/HelloWorld/Hello
You should see the text Hello World
in the browser.
Thanks to these pages for the info in this post
http://blog.eisele.net/2013/04/javaee-7-with-glassfish-on-eclipse-juno.html
https://stackoverflow.com/questions/24758298/glassfish-server-adapter-not-shown-in-list-in-eclipse