2.4 Eclipse Luna – More Than a Text Editor

Our use of Maven means that we are not reliant on a particular IDE. In principle, it is also possible to complete the rest of the workshop using a simple text editor to accomplish the programming. In practice, however, such an approach would never be used, since the use of an IDE increases productivity. For this reason, you should invest some effort in integrating Maven in an IDE of your choosing. We now wish to demonstrate how the integration of Maven with Eclipse (here, the current version, Luna) would be accomplished. Readers wishing to employ a different IDE should refer to the respective documentation and can move directly to section 2.5. Those wishing to complete the workshop with Eclipse should work through the following steps.

2.4.1 Installation of Eclipse

Eclipse is available to download in different distributions. Each distribution is preconfigured for a particular development goal. We are using the Eclipse IDE for Java EE Developers from the current Eclipse version, Luna (4.4), which is available for download at http://www.eclipse.org/downloads/ .

When downloading, be aware that Eclipse is available for Windows in both 32- and  64-bit versions (e.g. eclipse-jee-luna-R-win32.zip or eclipse-jee-luna-R-win32-x86_64.zip). Choose the version that is compatible with your Java installation. A folder containing all components of the IDE can be found in the ZIP archive under the name eclipse. It is sufficient for the installation that you extract the file to a location of your choosing (e.g. to a private user directory).

You can start Eclipse by running the file eclipse.exe. After startup, you will be prompted to create or choose an Eclipse workspace (any directory of your choosing) in which Eclipse can manage project files and metadata. Here, we recommend choosing the Java-EE-Workspace directory created in section 2.3.1, where our Maven project folder my-aktion is already located.

Eclipse will display a welcome page upon initial startup. The actual interface can be reached by clicking on the Workbench icon. The Eclipse Project Explorer does not currently recognize our project. However, the next steps should change this.

2.4.2 The Eclipse Plug-In m2e

The integration of Maven projects in Eclipse is accomplished by the plug-in m2e (Maven Integration for Eclipse). The plug-in comes preinstalled in the Eclipse version recommended in section 2.4.1; if you have this version installed, there is nothing more you need to do. If you are using a version in which the plug-in is not preinstalled, you must carry out the installation yourself. If you are in doubt, you can go to the menu item Help → About Eclipse and open a window with version information about your Eclipse installation. This window contains a list with logos of all the installed plug-ins. If m2e is installed, you will see a logo containing the “m2e” symbol.

Eclipse must be running in order for the plug-in to be installed; the computer must also be connected to the Internet. The installation of the plug-in can be initiated via the menu item Help → Install New Software …. However, we recommend that you use the distribution and version of Eclipse named in section 2.4.1 of this book.

2.4.3 Importing Maven Projects

We now want to utilize the functionality of the m2e plug-in to integrate our already-created project in Eclipse. We will open the Import dialog box by clicking on the menu item File → Import and enter “Maven” in the filter field to obtain a better overview. Finally, we will choose “Existing Maven Projects” as our source and click the “Next” button (see Fig. 2-2).

Choosing the import source for the Eclipse project
Fig. 2-2 Choosing the import source for the Eclipse project

We can choose the directory of our project (my-aktion) in the “Root Directory” field of the next dialog box. Eclipse analyzes the content of the directory and presents us with the pom.xml file – in which all project metadata is stored – as a suggested choice. We can choose the file by checking the appropriate box and then clicking the “Finish” button (see Fig. 2-3).

Selecting the my-aktion Maven project for import
Fig. 2-3 Selecting the my-aktion Maven project for import

Our project will now appear in the Eclipse project explorer. Expand the project folder and double-click on the file pom.xml. In the editor area of Eclipse, you should see a clearly arranged, graphical representation of the settings of your Maven project that are stored in the pom.xml file (see Fig. 2-4).

Section of the Eclipse view following the import of a Maven project
Fig 2-4 Section of the Eclipse view following the import of a Maven project

The import is now complete. The project files will continue to be stored in the location where the project was originally created. No data is copied into the actual Eclipse workspace as a result of the import; metadata about the project is the only thing that is stored there. If you chose the directory Java-EE-Workspace as your Eclipse workspace as suggested in section 2.3, the metadata and project data will be stored there.

Last but not least, we will change the text encoding for our project to UTF-8, the de facto standard of the Internet. To do this, we will right-click on our project and select “Properties” from the context menu. The character set can be defined in the Resource window of the resulting dialog box (see Fig. 2-5). Confirm your choice by clicking on the “OK” button.

Choosing the character set for the my-aktion project
Fig. 2-5 Choosing the character set for the my-aktion project

2.4.4 Deployment

You can now start the creation and deployment of the program directly from Eclipse; however, the WildFly application server must already be running (see section 2.2.3).

We will define a run configuration for the project in Eclipse. The relevant dialog box can be reached via the menu item Run → Run Configurations. In the dialog box, we can create a new run configuration for our project in the area “Maven Build”. To do this, we choose the item Maven Build and click on the symbol to create a new run configuration (New). In the following dialogue box, we can then enter a name for the run configuration (e.g. Deploy My-Aktion), the root folder of our project (e.g. C:\Users\MS\Java-EE-Workspace\my-aktion) and the Maven goals package wildfly:deploy (see Fig. 2-6). The configuration can be saved by clicking on the “Apply” button. The dialog box can then be closed by clicking the buttons “Run” or “Close”, the former of which will execute the immediate deployment of the project. Just as we did previously, we can create a run configuration to remove the project from the server (undeployment).

Dialog box for defining a start configuration for the Maven project
Fig. 2-6 Dialog box for defining a start configuration for the Maven project

As soon as we have executed the run configuration, it will be stored in Eclipse’s run history. This means that it can be executed easily later on (e.g. via the “Play” icon underneath the Eclipse menu or by clicking the menu items Run → Run History).

The m2e plug-in possesses other features that cannot be elaborated on here for reasons of space. These features enable the user to create an archetype-based Maven project from Eclipse. This method can be comfortably carried out using dialog windows and can be used in place of the method in section 2.3. However, this depends on the reader’s prior experience in using IDEs.

We have now integrated our current Eclipse installation with Maven using the m2e plug-in. A logical next step would be the integration of the WildFly application server in the IDE. The operation of the server in the IDE would eliminate the need to start it using the command line. JBoss offers a powerful Eclipse extension, JBoss-Tools (http://www.jboss.org/tools), a collection of Eclipse plug-ins that support JBoss and WildFly application servers and related technologies (similar offerings are available from other providers). We want to keep the complexity of tools used to a minimum in order to focus on the programming, and for this reason we will not explore this subject in any more detail at this time. However, we do recommend that you look into it independently as a next step after finishing the workshop or once you feel comfortable with the IDE.