-
Notifications
You must be signed in to change notification settings - Fork 2
Tutorial: a Java EE Web Profile application with nemo utils, part 1
Welcome to the tutorial "a Java EE Web Profile application with nemo-utils". In this tutorial, we start from scratch and give step-by-step instructions on how to use many of the features present in nemo-utils.
The running example for this tutorial is AutoTrab, a system which helps professors manage assignments students need to deliver.
The following tools and versions were used in this tutorial (newer versions of these tools might also work the same way):
- Java SE Development Kit 8 (download);
- Eclipse IDE for Java EE Developers, codename Luna (version 4.4) (download);
- WildFly 8.1, certified Java EE 7 (download);
- MySQL Community Server 5.6 (download);
- MySQL Workbench 6 (download);
- MySQL Connector/J JDBC Driver v5.1.33 (download).
Installation instructions vary according to operating system (Linux, MacOS or Windows), therefore we have not included detailed, step-by-step instructions on how to install these tools. In general, for Eclipse and WildFly it's enough to unpack them somewhere in your hard drive. We'll refer to the folder where you unpacked these tools as $ECLIPSE_HOME
and $WILDFLY_HOME
, respectively. The JDK and the MySQL server and workbench can be installed using an install wizard downloaded from their website or through your system's package manager (e.g.: apt-get
in Ubuntu Linux or any other Debian-based distributions). Finally, the Connector/J driver will be used during WildFly's configuration.
To deploy our application in WildFly during development more easily, it's recommended to integrate the IDE Eclipse with the application server WildFly. This is done through JBoss Tool, which can be installed through the following steps:
- Open Eclipse;
- Click on Help > Eclipse Marketplace...;
- In the Find field, fill in
JBoss Tools
, click the Go button and wait for the results to show up; - Locate the JBoss Tools (Luna) item at the results and click on its Install button;
- Select the item JBossAS Tools and continue the process, restarting Eclipse at the end of the process.
With JBoss Tools installed, after Eclipse is restarted switch to the Java EE perspective if not already in it (click on Window > Open Perspective > Other... and select Java EE) and open the Servers view (if not available at the bottom part of the perspective, click on Window > Show View > Servers). If you just installed Eclipse, the Servers view should be empty. Right-click its blank contents and select New > Server. Follow the wizard, selecting WildFly 8.x as the server type and pointing it to $WILDFLY_HOME
when asked for the server's directory.
At the end of the wizard, the WildFly server should be at the Servers view. Right-clicking on it allows you to start, stop, restart the server. Try starting the server and if everything is OK you should see as the last message in the Console view something like shown below. Then open http://localhost:8080/ and you should see WildFly's welcome page.
WildFly 8.1.0.Final "Kenny" started in 6957ms - Started 190 of 239 services (81 services are lazy, passive or on-demand)
A note about Java 8: if you have already updated your JRE/JDK to Java SE 8, and you're using WildFly 8.0, the server will not start correctly. In this case, either switch back to Java SE 7 or download and use WildFly 8.1, which should work properly with Java 8.
WildFly comes with an H2 Database driver configured. In this tutorial, however, we use MySQL, so we need to add its driver to WildFly's configuration. Follow these steps to do it (make sure the server is stopped for this):
-
In the folder
$WILDFLY_HOME/modules
, create the following directory structure:com/mysql/main
(we are using/
to separate sub-directories; Windows users should replace it with\
); -
Unpack the MySQL Connector/J JDBC Driver you downloaded earlier and copy the file
mysql-connector-java-5.1.33-bin.jar
to the newly created folder$WILDFLY_HOME/modules/com/mysql/main
. If you downloaded a different version of Connector/J, adjust the name accordingly; -
Still at
$WILDFLY_HOME/modules/com/mysql/main
, create a file namedmodule.xml
with the following contents (again if you downloaded a different version of Connector/J, adjust the name accordingly):<?xml version="1.0" encoding="UTF-8"?> <module xmlns="urn:jboss:module:1.1" name="com.mysql"> <resources> <resource-root path="mysql-connector-java-5.1.33-bin.jar"/> </resources> <dependencies> <module name="javax.api"/> </dependencies> </module>
-
Now open the file
$WILDFLY_HOME/standalone/configuration/standalone.xml
and look for the tag<subsystem xmlns="urn:jboss:domain:datasources:2.0">
. Inside this tag, locate<datasources>
and then<drivers>
. You should find the H2 Database driver configuration there. Next to it, add the configuration for MySQL Connector/J, as following:<driver name="mysql" module="com.mysql"> <driver-class>com.mysql.jdbc.Driver</driver-class> </driver>
You should now be ready to develop a Java EE project in Eclipse, deploying it in WildFly and configuring it to use MySQL database for persistence. The above steps need to be done just once for all projects which will use these tools. In the next step we start AutoTrab with some project-specific configurations.