Unlike NetBeans, Eclipse does not come with GlassFish support out of the box. Fortunately, it is very easy to add GlassFish support. Eclipse can be downloaded from http://www.eclipse.org.
Note
In this section, we assume that the Eclipse IDE for Java EE developers is installed. This version of Eclipse includes tools for Java EE (JSF, JPA, EJB, and so on) development.
In order to integrate Eclipse and GlassFish, we need to download the GlassFish server adapter for Eclipse. To do this, we need to right-click on the Servers tab at the bottom of the Java EE perspective and select New | Server:
We then need to click on the Download additional server adapters link in the window that pops up:
After doing so, a list of all available server adapters will be shown:
We simply need to select GlassFish and click on the Next > button.
At this point, we need to accept the license agreement and click Finish.
After the GlassFish server adapter for Eclipse is downloaded, we are told that it is strongly recommended to restart Eclipse. It is a good idea to do so.
After Eclipse restarts, the GlassFish server adapter is fully installed, and we are ready to deploy our applications to GlassFish straight from Eclipse.
To demonstrate the integration between GlassFish and Eclipse, we will use a project of type Dynamic Web Project, but the procedure is very similar for other Java EE project types.
To create a new Dynamic Web Project, all we need to do is click on File | New | Dynamic Web Project.
When creating a Dynamic Web Project, Eclipse will ask, among other things, for the Target runtime for the project. The target runtime is "Eclipse Speak" for a Java EE application server.
To select GlassFish as our target runtime, we need to click on the New... button, then select GlassFish v3 Java EE 6 from the GlassFish folder.
After clicking Next >, we need to indicate the directory where GlassFish is installed:
We then need to indicate the domain directory, name, administrator Id, and password for our domain. Most of these fields have sensible defaults. In most cases, the only field we need to enter is the password.
After we finish creating our project, we should see GlassFish in the Servers view, which is typically at the bottom of the screen:
If the Servers view is nowhere to be seen, it can be opened by clicking on Window | Show View | Servers.
At this point, we are ready to start developing our application. When we are at a point where we need to deploy it, we can do so by clicking on the GlassFish server icon in the Servers view and selecting Publish:
At this point, Eclipse will build, package, and deploy the application.
For web applications, we can execute the application as soon as it is deployed by right-clicking on the project and selecting Run As | Run on Server:
At this point, Eclipse will build, package, deploy the application, and open it in a browser window embedded in Eclipse.
If we wish to debug the application using Eclipse's debugger, we can do so by right-clicking on the project and selecting Debug As | Debug on Server. This will cause Eclipse to start or restart GlassFish in debug mode, if necessary, and deploy the application. We can then debug it using Eclipse's built-in debugger.