About Markus Eisele

Markus is a principal technology consultant working for msg systems ag in Germany. Markus is a software architect, developer and consultant. He also writes for IT magazines. Markus is speaking at different conferences about his favorite topics. He is also part of the Java EE 7 expert group.

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
 

Related Whitepaper:

Functional Programming in Java: Harnessing the Power of Java 8 Lambda Expressions

Get ready to program in a whole new way!

Functional Programming in Java will help you quickly get on top of the new, essential Java 8 language features and the functional style that will change and improve your code. This short, targeted book will help you make the paradigm shift from the old imperative way to a less error-prone, more elegant, and concise coding style that’s also a breeze to parallelize. You’ll explore the syntax and semantics of lambda expressions, method and constructor references, and functional interfaces. You’ll design and write applications better using the new standards in Java 8 and the JDK.

Get it Now!  

Leave a Reply


+ three = 12



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use
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.

Sign up for our Newsletter

15,153 insiders are already enjoying weekly updates and complimentary whitepapers! Join them now to gain exclusive access to the latest news in the Java world, as well as insights about Android, Scala, Groovy and other related technologies.

As an extra bonus, by joining you will get our brand new e-books, published by Java Code Geeks and their JCG partners for your reading pleasure! Enter your info and stay on top of things,

  • Fresh trends
  • Cases and examples
  • Research and insights
  • Two complimentary e-books