Book Image

WildFly Cookbook

Book Image

WildFly Cookbook

Overview of this book

Table of Contents (23 chapters)
WildFly Cookbook
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Software prerequisites


WildFly runs on top of the Java platform. It needs at least a Java Runtime Environment (JRE) version 1.7 to run (further references to versions 1.7 and 7 should be considered equal—the same applies for versions 1.8 and 8 as well), but it also works perfectly with the latest JRE version 8.

As we will also need to compile and build Java web applications, we will need the Java Development Kit (JDK), which provides the necessary tools to work with the Java source code. In the JDK panorama we can find the Oracle JDK, developed and maintained by Oracle, and OpenJDK, which relies on community contribution.

Nevertheless, after April 2015, Oracle will no longer post updates of Java SE 7 to its public download sites, as mentioned at http://www.oracle.com/technetwork/java/javase/downloads/eol-135779.html. Also, keep in mind that the Java Critical Patch Updates are released on a quarterly basis; thus, for reasons of stability and feature support, we will use the Oracle JDK 8, which is freely available for download at http://www.oracle.com/technetwork/java/javase/downloads/index.html.

While writing this book, the latest stable Oracle JDK is version 1.8.0_31 (as well as 8u31). Hereby, every reference to Java Virtual Machine (JVM), Java, JRE, and JDK will be intended Oracle JDK 1.8.0_31. To keep things simple, if you don't mind, use that same version.

In addition to the JDK, we will need Apache Maven 3, which is a build tool for Java projects. It is freely available for download at http://maven.apache.org/download.cgi. A generic download link can be found at http://www.us.apache.org/dist/maven/maven-3/3.2.5/binaries/apache-maven-3.2.5-bin.tar.gz.

Getting ready

To fully follow the recipes in the book, using the same environment is a fundamental requirement. As I cannot replicate the same recipe to suit different settings (such as Windows, Mac, and Linux), I'll use Linux (actually, Fedora 21) as the base operating system.

If you are running a different system and you want to carefully follow what's in the book, you can easily install and run Fedora 21 inside a virtual machine using the VirtualBox software, available at https://www.virtualbox.org/wiki/Downloads.

  1. Choose the version that is compatible with your actual system. You can install Fedora 21 by downloading its image at https://getfedora.org/en/workstation/.

    Note

    The installation of the above software is out of the scope of this book.

  2. To install the Oracle JDK, you need to open your browser and point it to http://www.oracle.com/technetwork/java/javase/downloads/index.html.

  3. Once there, click on the JDK download link, as depicted in the following image:

  4. The link will take you to the download page, where you first need to mark the option of Accept License Agreement to enable the links, as depicted in the following screenshot:

  5. As you accept the agreement, all the links get activated. Choose the one that best fits your hardware and operating system.

    I'm running a Fedora 21 Linux machine, with a 64-bit hardware support, thus I'll use the jdk-8u40-linux-x64.tar.gz bundle. I could have used the RPM bundle, but I prefer installing the archive version to better fit my needs in terms of paths; what goes where.

  6. Next, we will create a folder named WFC, which stands for WildFly Cookbook to store the contents of all the necessary software, codes, and files to follow all the recipes of the book. Open your terminal application and run the following command:

    $ cd && mkdir WFC
    

    Note

    The WFC folder is used just to not interfere with your current environment.

How to do it…

  1. Choose the package archive; once the download is complete, open your command line and extract its contents to the WFC folder as follows:

    $ cd ~/WFC && tar zxvf jdk-8u40-linux-x64.tar.gz
    

    This will extract the Oracle JDK software into the jdk1.8.0_40 folder, inside the WFC folder starting from your home folder. For convenience, we will use a different folder name, like jdk8, to refer to the preceding JDK installation folder. Run the following command:

    $ cd ~/WFC && mv jdk1.8.0_40 jdk8
    

    Now we need to set the JAVA_HOME environment variable and make the JDK commands available from our shell (also terminal).

  2. Open a text editor of your choice, and add the following directives to the .bash_profile file placed in your home folder:

    export JAVA_HOME=~/WFC/jdk8
    export PATH=$JAVA_HOME/bin:$PATH

    The preceding two commands will set the JAVA_HOME variable and export the JAVA_HOME/bin path into your PATH system variable, respectively. The tilde ~ symbol is a shortcut to the user home directory in Unix-like systems.

    For the changes to take effect, you can either log out and log back in, or just issue the following command:

    $ source ~/.bash_profile
    
  3. Once you are done with the installation phase, test your new environment by executing the java -version command in your terminal application and you should see (more or less) the output as depicted in the following image:

  4. Next, we need to install Apache Maven 3. If you haven't downloaded it yet, click on the following link:

    http://www.us.apache.org/dist/maven/maven-3/3.2.5/binaries/apache-maven-3.2.5-bin.tar.gz

  5. Once the download is complete, open your command line and extract its content to the WFC folder:

    $ cd ~/WFC && tar zxvf apache-maven-3.2.5-bin.tar.gz
    

    This will extract the Apache Maven (also known as Maven) software into the apache-maven-3.2.5 folder, inside the WFC folder, starting from your home folder. For convenience, we will use a different folder name, like maven, to refer to the preceding Maven installation folder. Run the following command:

    $ cd ~/WFC && mv apache-maven-3.2.5 maven
    

    Now we need to set the M2_HOME environment variable and make Maven's commands available from our shell (also terminal).

  6. Open a text editor of your choice, and add the following directives to the .bash_profile file placed in your home folder:

    export M2_HOME=~/WFC/maven
    export PATH=$JAVA_HOME/bin:M2_HOME/bin:$PATH
    

    The preceding two commands will set the M2_HOME variable and export the M2_HOME/bin path into your PATH system variable, respectively. The tilde ~ symbol is a shortcut to the user home directory, in Unix-like systems.

    For the changes to take effect, you can either log out and log back in, or just issue the following command:

    $ source ~/.bash_profile
    
  7. Once you are done with the installation phase, test your new environment by executing the mvn -version command in your terminal application and you should see (more or less) the output as depicted in the following image:

  8. Last, but not the least, we will need to install the git, which is a distributed revision control system. It is mainly used with the source code, but it's also used as a configuration repository. To install the git tool, we will rely on the yum software manager, which makes the installation process easy. Open a terminal and do as follows:

    $ sudo yum -y install git
    
  9. Once done, try to hit the following command:

    $ git version
    git version 2.1.0
    

There's more…

Now that we have the git installed, we can proceed to download the code repository (or repo) used for this book, available on my GitHub account at the following URL: https://github.com/foogaro/wildfly-cookbook.git.

You can git-clone the repository or just download it as a ZIP archive. Either way, create a folder named github into the WFC folder and place the source into it.

Using the git-clone command, do as follows:

$ cd ~/WFC
$ mkdir github
$ cd github
$ git clone https://github.com/foogaro/wildfly-cookbook.git

Once the git has done cloning the repo, you will find a new folder named wildfly-cookbook where you can find all the projects used for the book.

To build a project, just go into the proper folder and execute the maven-package command.

For example, to build the project example, do as follows:

$ cd ~/WFC/github/wildfly-cookbook/example
$ mvn -e clean package

The preceding commands builds the project, and generate the web application artifact into a folder named target. There you can find the application example.war, ready to be deployed.

OK, we have finally finished installing all the software that we will need and use within the book. Just to be sure you are not missing any piece, you should have an environment as depicted in the following image: