Markus Eisele

About Markus Eisele

Markus is a Developer Advocate at Red Hat and focuses on JBoss Middleware. He is working with Java EE servers from different vendors since more than 14 years and talks about his favorite topics around Java EE on conferences all over the world. Follow him on Twitter @myfear.

JavaEE 7 with GlassFish on Eclipse Juno

Java EE 7 is hot. The first four JSRs passed the final approval ballot recently and GlassFish 4 reached promoted build 83 in the meantime. If you are following my blog you know, that I do most of my work with NetBeans. But I indeed recognize, that there are other IDE users out there which also have a valid right of also testdriving the latest and greatest in enterprise Java.

The GlassFish Eclipse Plugins

The starting place for Eclipse are the GlassFish Eclipse plugins. They moved into the Oracle Enterprise Pack for Eclipse (OEPE) project a while back and are still there to be installed and configured separately. The easiest way to get them is to use the
 
pre-packaged OEPE bundle. Simply download the suitable version and get started. If you already have you favorite Java EE Eclipse version you can also use the java.net update site for Eclipse Juno. The OEPE package contains oficial releases (more stable, tested) of GF plugins and new releases come one or two times per year. The update sites on java.net contain developer builds that are released as needed, typically a lot more often then OEPE. You can download from whatever meets your needs.

Install the Plugin


This works as expected. If you stick to the update site you simply go to Preferences->Install/Update->Available Software Sites and make sure that the above mentioned site is defined and checked. Install the GlassFish Tools and the Java EE 6 and/or Java EE 7 documentation and sources according to your needs. Click next two times, read through the license and check accept. Click Finish to install. The download gets everything in place and you have to finish the installation with a re-start.

Starting a new Java EE 7 Project

Once that it done you can start with configuring your GlassFish 4.0 domain. The simplest way is to create a New Project > Other > Web > New Dynamic Web Project and select the “New Runtime” button next to target runtime. The New Server Runtime Environment dialogue pops up and you can select “GlassFish 4.0″ from the GlassFish folder. Make sure to select a Java SE 7 JDK and the appropriate GlassFish Server Directory to use (or even install). In this example I am using the latest promoted build 83 freshly downloaded from the GlassFish website. Click Finish. Now add a simple servlet which does nothing spectacular but use some Java API for Processing JSON to write a simple JSON string.

protected void doGet(HttpServletRequest request,
   HttpServletResponse response) throws ServletException, IOException {
  response.setContentType("application/json");
  PrintWriter out = response.getWriter();

  JsonObjectBuilder builder = Json.createObjectBuilder();
  builder.add(
    "person",
    Json.createObjectBuilder().add("firstName", "Markus")
      .add("lastName", "Eisele"));
  JsonObject result = builder.build();
  StringWriter sw = new StringWriter();
  try (JsonWriter writer = Json.createWriter(sw)) {
   writer.writeObject(result);
  }
  out.print(sw.toString());
 }


Right click the project and select “Run as ..” > “Run on Server” > GlassFish 4.0. Now point your browser to localhost and see the result working. The server view gives you the well know overview about your instance. And there you go. Have fun doing your Java EE 7 developments with Eclipse
 

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


− three = 5



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