« All Software Development Articles

WildFly 10.1.0.Final Tutorial using JBoss Tools in Eclipse

6/27/2017

Introduction

This article describes how to get started developing locally on WildFly (formerly known as JBoss AS) using the JBoss Tools plugin in Eclipse. The steps are written for a Windows system, however a Linux user should be able to follow along with only minor adjustments.

WildFly 10 is a Java EE 7 compliant application server. The features (JSRs) included in Java EE 7 are listed on the Java EE version history Wikipedia page https://en.wikipedia.org/wiki/Java_EE_version_history#Java_EE_7_.28June_12.2C_2013.29.

Installing WildFly

Before you start, you must have JDK 8 and Eclipse IDE for Java EE Developers Neon (4.6.1 or above) already installed. Also, ensure the JAVA_HOME environment variable https://superuser.com/questions/949560/how-do-i-set-system-environment-variables-in-windows-10 is set to your JDK path e.g. C:\Program Files\Java\jdk1.8.0_101.

To begin, download WildFly 10.1.0.Final at http://wildfly.org/downloads/. Select the download with the description "Java EE7 Full & Web Distribution" and choose the .ZIP format.

Installation is simply extracting the archive. You should extract it to your user folder e.g. C:\Users\username\wildfly-10.1.0.Final, or another location where you have full permissions. In the WildFly 10 documentation the Getting Started Guide https://docs.jboss.org/author/display/WFLY10/Getting+Started+Guide gives a brief overview of the directories and configuration files in the distribution.

You're now ready to launch WildFly. Run C:\Users\username\wildfly-10.1.0.Final\bin\standalone.bat from a Command Prompt or PowerShell (or double-click the file icon). The window will display output and remain open while the server is running. Once the server is started you can open http://localhost:8080/ in a browser and see the "Welcome to WildFly 10" landing page. To stop the server, press CTRL+C in the Command Prompt window and press 'y' then Enter when asked to terminate batch job.

Configuration

For management operations you must create a management user. Run C:\Users\username\wildfly-10.1.0.Final\bin\add-user.bat from a Command Prompt or PowerShell (or double-click the file icon). In the subsequent prompts choose the type 'Management User', enter a username and password, and leave the groups line blank. Next, at the confirmation prompt type 'yes' and at the question regarding connecting to another AS process type 'no'. Afterwards, you can see where the user credentials are stored in the file C:\Users\username\wildfly-10.1.0.Final\standalone\configuration\mgmt-users.properties.

The Administration Console has features to monitor the system, manage deployments, and create datasources. To open, start the standalone server and browse to http://localhost:9990/console. Some options are also available using a the command line or by editing the configuration files directly. See the Admin Guide https://docs.jboss.org/author/display/WFLY10/Admin+Guide for more details.

Installing JBoss Tools in Eclipse

The main reason to add the JBoss Tools plugin to Eclipse is for the WildFly server runtime. To install, open the Eclipse Marketplace window from Eclipse's Help menu. Search for 'jboss' and find JBoss Tools 4.4.4.Final (it is also close to the top in the Popular tab) and click Install. Confirm the default features and accept the licenses to install the plugin.

I believe the only required feature is JBoss AS, WildFly & EAP Server Tools and dependent features, if any, although I haven't experiemented with limiting the features to only this one.

For me, as installation progressed I received errors about two specific features; Red Hat Container Development Kit and OpenShift. I chose to 'Keep my installation the same' as I didn't want to modify my base Eclipse install for features that are not relevant to regular Java EE development. If your Eclipse version is more up-to-date you may not encounter this issue or you can choose to update your installation.

Adding Your Server

To set up the server first you must configure a Runtime Environment. Open Perferences from the Window menu, expand Server and select Runtime Environments. Click Add and choose WildFly 10.x Runtime. In the next window, keep the Name as 'WildFly 10.x Runtime', set the Home Directory to C:\Users\username\wildfly-10.1.0.Final, set the execution environment to JavaSE-1.8, then keep the Server base directory as 'standalone' and the configuration file as 'standalone.xml'.

Next you set up the Server to be used by our projects. In the Servers tab of the Workbench (if this tab is not visible open the Windows menu, expand Show View, and click Servers) right-click in the empty space expand New and click Server. For server type select WildFly 10.x. The Server host name is localhost and Server name can be 'WildFly 10.x' which are the defaults. On the next window confirm the server is 'Local', controlled by 'Filesystem and shell operations', the 'Server lifecycle is externally managed' box is not checked, and the WildFly 10.x Runtime is selected, then click Finish.

The server is now available in the Servers tab. You can start and stop it from the right-click menu. If you start the server from within Eclipse you'll see the server's command line output in the Console tab. However, you can still use the standalone.bat script from the bin folder if you'd rather have the server in it's own console window. Since we chose Filesystem deployments, the Publish function in the menu will work whether we start the server in Eclipse or out. Sometimes it's useful to be able to search the console output from within Eclipse. Another alternative is to view the server log file, which is a copy of the command line output, and is available at C:\Users\username\wildfly-10.1.0.Final\standalone\log\server.log.

Your First Project

To test the server you can create a new project. Create a new Dynamic Web Project, name it WildFlyTutorial, and ensure the WildFly 10.x Runtime is selected. All the other new project defaults should all be fine for this test so click Finish.

Under the new project's WebContent folder create Test.jsp and edit it a little. To view this new JSP right-click on the project, expand Run As, and click Run On Server. Then choose WildFly 10.x, check 'Always use this server', and click Finish. Eclipse opens a browser tab (with error because it doesn't browse directly to Test.jsp) but close it and browse to http://localhost:8080/WildFlyTutorial/Test.jsp in an external browser. You can also manage which projects are deployed to this server by right-clicking the server in the Servers tab and clicking Add and Remove.

When editing your source code updates to the WebContent folder are deployed upon save. This includes static resources, JSPs, and static WEB-INF content. At this time take a look at the contents of C:\Users\username\wildfly-10.1.0.Final\standalone\deployments\WildFlyTutorial.war. You'll see the project as it's being served by WildFly.

To see how compiled content is handled expand your project's Java Resources, right-click src, and create a new package. Right-click the new package and create a new Servlet, name it TestServlet, and Finish with the default settings. At this time note in the deployments folder under WildFlyTutorial.war\WEB-INF\classes\com\stevewakeford\WildFlyTutorial there is no class file.

For compiled resources you must build the project (CTRL+B is the hotkey) then republish using the Servers tab. Under your WildFly 10.x server right-click the WildFlyTutorial project click Full Publish. You can see the console performing the undeploy then deploy. Once this process is complete you can browse to http://localhost:8080/WildFlyTutorial/TestServlet and see the output.

To skip the build step, which is easy to forget, go to the Preferences window, expand General, and in the Workspace settings enable Build automatically and Save automatically before build.

Done

You're now ready to use JBoss Tools in Eclipse to develop Java EE applications on WildFly 10. If this was helpful let me know on my contact page.

Have a nice day.