Jboss AS Wildfly for Java developer tutorial

How often do You face situation when local development is done using simple Tomcat or Jetty container? Very often backed up with JRebel? Yeah, that’s what I thought 😉 It works like a charm but finally there is always an ultimate problem – deployment to dev/integration/prod environment. Why it is an issue? Because usually it is application server we have to deal with. And here comes the problem.

I’ve faced such situation many times. The expected truth is that it should make no difference. Servlet container is also a part of application server. Yes, I can agree to that, but very often there is some kind of a problem during application deployment in application server. If we have always-ready-to-fast-response-admin-team it is no such big deal. But what happens if reality is not so great – and the only thing we have is log file that does not tell us anything? We have a problem for sure. And that is exactly my point. It is better to understand a little bit of our application server. That is the subject of this blog post. I will show how to install and configure local instance of JBoss Wildfly and deploy simple application to it. I do not see this post as comprehensive tutorial – it is just some kind of ‘lessons learned’ to me. Let’s go.

Versioning, terminology and WTH is EAP?

In the good old days everything was simple. There was JBoss Application Server and that was it. I remember when I entered Java world version in use was 4.x one. As years went by I sometimes came across next versions of that server in my contractor’s career, but never paid special attention as I mostly used Weblogic. Some time ago I found out that there is some kind of new kid in town – Wildfly. After a little bit of digging I learned that it as good old Jboss AS but with different name. Why did that happen?

The answer is simple – JBoss Enterprise Application Platform (or for short Jboss EAP) emerged. EAP is a commercial product – it is usually much more ahead with bugfixes that community version of the server. To use it in a production mode you have to pay Jboss. On the other side there is still good old Jboss AS which is now called Wildfly mostly because there was very similar versioning of EAP and JBoss AS. The truth is – if You have EAP used in production (or dev/integration env) and You want to make sure Your app will work there use this site to find out which application’s server version You need and then download it and run. Wildfly is a name for newer version of Jboss AS (starting from version 8) and as far as I can see it, so far it is not yet used in EAP at all.

Despite what I have written above I decided to use latest stable Wildfly in my tutorial. Why? Because as I browsed through latest EAP and Wildfly documentation and folders I see no difference. What is more important – Wildfly can be downloaded ‘by hand’ from its page, with EAP registration is required. And I know for how many people that can be a concern 😉 So just download 8.2.0.Final and we can start.

Installation, folder structure and first run

Installing JBoss is fairly easy – just download ZIP archive and unpack it. Piece of cake. Now we can proceed to the unpacked directory to the bin folder. There are files (executables for both Windows and Linux). What should we use? The idea here is to understand the modes in which server can be run. There are two:

a) standalone mode – which is sufficient for 99% of usages on developer’s machines. It does not mean that it is not suitable for production machines. Server running in standalone just run in one process and whole configuration is specific only to this one machine.

b) domain mode – it is mostly used in production environments as it provides way to keep server’s config consistent using just one machine.

Domain mode does not mean clustering! There is no problem to create cluster using both – standalone or domain mode.

In order to understand basic concepts which are important to Java developers I will use standalone mode in this post. My idea is to present domain and clustering in the future. Sometimes I will mention things related to domain mode (in comparison to standalone).

Having said that we concentrate only on bin/standalone.bat executable (I am working on Windows, Linux users should be familiar with .sh scripts). To separate run-scripts from configuration there is additional config file named standalone.conf.bat, that is used by run-script to customize configuration. Usually when there is no previous JBoss (which in fact means there is no global JBOSS_HOME variable set) we need no additional configuration (besides set JAVA_HOME). Before we start the server we can look around bin folder:

a) adduser.bat – adds user to the server security realm.
b) application-client.bat – it starts lightweight container for client applications that communicate with JBoss. More can be found in this link.
c) init.d – folder containing example run-scripts for running JBoss as a service on linux machine. Be careful! The script may need tweaking to run seamlessly on your system.
d) jboss-cli – I will describe this utility later. It is management utility allowing admins to change server configuration from command line
e) jconsole.bat – widely known tool to monitor working JVM
f) jdr.batJBoss Diagnostic Reporter. It will collect useful data from the server, resulting in ZIP file which can be used eg. by support from JBoss
g) run.bat – legacy launch script, not used
h) vault.bat – command line tool to secure sensitive data
i) wsconsume/wsprovide – are command line tools (and also Ant tasks) to generate webservice from WSDL (wsconsume) or from endpoint class (wsprovide)

Now we know our way around. We can finally start Wildfly in standalone mode and the end of run process should be logged similar to this:

21:00:18,761 INFO [org.jboss.ws.common.management] (MSC service thread 1-3) JBWS022052: Starting JBoss Web Services – Stack CXF Server 4.3.2.Final
21:00:19,045 INFO [org.jboss.as] (Controller Boot Thread) JBAS015961: Http management interface listening on
21:00:19,048 INFO [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on
21:00:19,050 INFO [org.jboss.as] (Controller Boot Thread) JBAS015874: WildFly 8.2.0.Final “Tweek” started in 16305ms – Started 184 of 234 services (82 services are lazy, passive or on-demand)

In order to check if everything is ok we can download sample applications for Wildfly from official GitHub page. The most basic is of course helloworld. Just go to the folder You cloned the code and issue the command (with server still running):

mvn clean package wildfly:deploy

In server’s log we should see something like this:

21:21:39,944 INFO [org.wildfly.extension.undertow] (MSC service thread 1-8) JBAS017534: Registered web context: /wildfly-helloworld
21:21:40,894 INFO [org.jboss.as.server] (management-handler-thread – 1) JBAS018559: Deployed “wildfly-helloworld.war” (runtime-name : “wildfly-helloworld.war”)

Right now the only thing left to se is working application. We can visit http://localhost:8080/wildfly-helloworld and see if everything is ok. There should be plain and simple Hello World message on the screen.

Server’s administration

Main idea behind Jboss lately is to avoid editing XML files in order to perform administrative tasks. It is good thing – while doing changes using prepared application it is possible to perform additional validation, which avoid errors. By default console application is accessible on port 9990, although if we visit it right now that is the view we are going to see:


As mentioned we must create user to access the app. Remember the list of additional scripts in bin folder? There was script add-user.bat – we are going to use it right now. Process is simple – just add new Management User and follow the questions on the screen. When finished, You can log in http://localhost:9990/console and see something like this.


It means we have admin user and server is working properly. More about admin-related tasks can be found on Akquinet.

So how to deploy an app?

When we do not want to use Maven plugins deployment process is fairly simple.

  • GUI application – just visit Deployments tab in this app and point to existing file.
  • Auto deploy – the same way as it was done in previous versions. Just copy new file to standalone/deploy folder and it will be picked up by server automatically.
  • CLI deployment – quite obvious (example taken from the docs):
    // run jboss-cli.bat
    // type 'connect' to connect to running instance
    [standalone@localhost:9999 /] deploy ~/Desktop/test-application.war
    'test-application.war' deployed successfully.
    [standalone@localhost:9999 /] undeploy test-application.war
    Successfully undeployed test-application.war.

Where are my logs?

At the end I will describe problem I’ve faced while deploying my app to development server. The title is right – I could not find my log files. On my local machine slf4j and logback were used, creating two separate files with logs. One for SQL statements and one for everything else. When I deployed application to the Jboss it did not work.

Wildfly has modular architecture. Logging is performed by logging subsystem that can be configured in several ways (yep, console application is one of them). But before that subsystem kicks in, server logging during startup is done via logging.properties file, that resides in configuration directory. I saw that file and was sure that this is final config. Unfortunately it is not. As I’ve mentioned – it is used only before logging subsystem starts.

This subsystem has simple property – add-logging-api-dependencies, that when set to true will force server to provide logging libraries and dependencies. That makes my application’s logging config not working. To fix that I could change above setting, but it was impossible as it affects whole server. So there is another solution. I’ve added file jboss-deployment-structure.xml to my WEB-INF. It is one of deployment descriptors recognized by JBoss. The file looked like this:

            <module name="org.slf4j" />
            <module name="org.slf4j.impl" />
            <module name="org.slf4j.api" />
            <module name="org.slf4j.jcl.over.slf4j" />
            <module name="org.apache.log4j" />
            <module name="ch.qos.logback.core" />
            <module name="ch.qos.logback.classic" />

It excludes modules with given name, but can be done better as described in this forum thread

     <!-- exclude-subsystem prevents a subsystems deployment unit processors running on a deployment -->  
     <!-- which gives basically the same effect as removing the subsystem, but it only affects single deployment -->  
        <subsystem name="logging" />  

After deployment everything started to work as expected.

JavaScript Patterns book review

lrg I have never actually studied JavaScript. It was something that came with the job, back then, when I started working as PHP programmer. I have no problem with jQuery usage and also with jQuery Ui components, but this is all. Reading JavaScript Patterns was like a breathe of a fresh air again.

The book concentrates on good practices and patterns used in proper JavaScript coding. It does not cover very much of the language internals but shows why one approach is good and why another is bad. Therefore there is also a great piece of knowledge gained in the process, what is important, every chapter is full of practical solutions. All aspects of JavaScript programming – scalar values, object creation, functions or code conventions have been described. Intentionally or not, the book is short and cohesive course of JavaScript itself.

Maybe it is just me, but all articles or papers I’ve read about JavaScript in the past was heavily linked with the browser. That is not an issue here. Although there is separate chapter describing DOM and browsers, all knowledge and examples were given without browser in mind. You can run all examples eg. in Nashorn.

It seems that mamy review is short. But that is the beauty of book I am reviewing – there is no doubt that You should read it. Despite working with JavaScript or not – it will just make You a better coder.

Model variables for all views in Thymeleaf 2.1 with Spring MVC

Recently I’ve stumbled upon quite common problem – how to inject a few variables to every Thymeleaf view in application. Of course there is @ModelParam annotation, I could use interceptor or @ControllerAdvice. All solutions are described on StackOverFlow (it is about controllers).

The problem was that I wanted to put Maven build information in that model (to show version and build time in footer). Therefore I did not need application-scope wiring, as build informations are available during Spring’s container startup. So I’ve found another solution dealing with model itself on the lower level – pure XML configuration. There is a special property in ThymeleafViewResolver that can be used – static variables. So code sample can look like this:

<bean id="thymeleafViewResolver" class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
    <property name="templateEngine" ref="templateEngine" />
    <property name="characterEncoding" value="UTF-8" />
    <property name="staticVariables">
                <entry key="myModelVariableIWantToSet" value="My model variable value" />
                <!-- All placeholders taken from context:property-placeholder tag can be used as value-->

All defined variables are put into all Model instances that are linked to Thymeleaf views. If You are just serving plain JSON it does not go there – that can be expected behaviour or not! Be aware of that fact.

Spring MVC Revisited

Recently I had an opportunity to play with architecture of a new internal app in my company. In order to properly do my job I’ve reread whole Spring MVC documentation. It was very refreshing ( after a while of using this framework ) to discover several new things. My goal is just to present short list of features with links to docs. There is no point in reinventing the wheel 😉

Matrix Params

Ever wanted to provide more data with just URI? Matrix variables are the best way to do this. Just look at the URI presented:


Yep, you can process it and extract data very easilly. Above URI and nice blog posts about them can be found on Captain’s Debug blog (second part with code snippets here).


I am used to using ModelAttribute annotation, mostly on update/save actions in my controllers. What I did not know is that this annotation can be also used with methods. Remember all the situations when You must fill several model variables with data just in order to render them as eg. SELECT-tag values? Now you create just one method in controller and annotate it with @ModelAttribute to put method return value in model. More information can be found in spring docs.

Flash attributes with redirects

I remember problems with simple flash redirects a few years back (circa early Spring’s version 3, flash attributes were introduced in 3.1). Today they are even better handled – You do not need to manually put them into FlashMap. There is a nice class RedirectAttributes which greatly improves coders’ quality of life. Just look at this code:

@RequestMapping(value = "/accounts", method = RequestMethod.POST)
 public String handle(Account account, BindingResult result, RedirectAttributes redirectAttrs) {
   if (result.hasErrors()) {
     return "accounts/new";
   // Save account ...
   redirectAttrs.addAttribute("id", account.getId()).addFlashAttribute("message", "Account created!");
   return "redirect:/accounts/{id}";

Above example comes from RedirectAttributes API, but there is also short Spring doc section and simple tutorial.

BindingResult order

There is nothing new in BindingResult interface. But what cought my attention is the need for this interface be declared as first parameter after @ModelAttribute in controller’s method to work!. I was not aware of that and I assume knowing that can be real time-saver. Short example:

public String addNewBlogger(@ModelAttribute("blogger") Blogger blogger,
            ModelMap map, BindingResult results) 

The above example will not work properly. You will get either exception or application’s logic will behave strangely (depends mostly on error handling and view layer/resolver). Proper solution look like this:

public String addNewBlogger(@ModelAttribute("blogger") Blogger blogger, BindingResult results, ModelMap map) 

Simple creation of URIs

Very often there is a need to create a new URI, eg. to perform redirect. Concatenating string values with parameters is not often clean and simple (not to mention it is very error prone). In order to ease developers’ life Spring provides very dsl-like solution with MvcUriComponentsBuilder class. More can be found in documentation.

[Links] Strings concatenation in Java and Groovy

Lately I had a discussion at work regarding strings concatenation in Java and Groovy. To clear the view I hit the web and found several interesting posts about it that I want to share but the truth is after reading this I know less than before 😉


There is a little bit more – while searching the web I have found neat solution in latest Java with a class StringJoiner which allows programmer to forget about pluses or several <em>append()</em> calls.

Hacking as game

Recently I’ve been interested in several different areas of computer science, one of which is web/system security. I am not trying to join Anonymous or something ;), but You can never have enough knowledge. Due to that fact I’ve stumbled upon a nice page, with some kind of CTF-like games or tasks, which can greatly increase Your knowledge about linux, web and security. I have not ended all tasks but it can be really fun. Here is the page – http://overthewire.org/.

Shortcut for jRebel executor in Intellij Idea

I have recently started working again with Intellij Idea with jRebel. This tool-combo is one of the best things that ever happened to me, although I faced a little problem.

When running Tomcat instance from Intellij (with jRebel configured properly) You should use a little rocket icon on your toolbar.


After clicking it Tomcat starts and there is console window at the bottom of the screen. But imagine the situation when this window is hidden – You toggled fullscreen mode or searched for something. The only way to show that window again was to use mouse and go to menu View->Tool Windows and the find JRebel Executor. I tried to assign shortcut for this (similar to simple Run action), but I could not find proper action on the shortcut list (menu File->Settings->Keymap). The solution is simple – Tomcat with JRebel must be TURNED ON to create this shortcut!! While running Intellij Idea will show additional item for JRebel executor in actions list! Just assign it shortcut You want and viola, it works.