Product docs and API reference are now on Akamai TechDocs.
Search product docs.
Search for “” in product docs.
Search API reference.
Search for “” in API reference.
Search Results
 results matching 
 results
No Results
Filters
Deploy Clojure with Immutant and WildFly on Ubuntu 14.04
Traducciones al EspañolEstamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.
DeprecatedThis guide has been deprecated and is no longer being maintained.
Clojure is a general-purpose programming language with an emphasis on functional programming. It is a dialect of the Lisp programming language running on the Java Virtual Machine (JVM). While Clojure allows you to write elegant and concise code, its ability to make use of the existing JVM infrastructure, such as libraries, tools and application servers, makes it also a very practical choice.
This guide will show how to deploy a Clojure application to WildFly - the popular open-source Java application server developed by RedHat. To simplify the deployment process, a suite of libraries called Immutant will be used.
Before You Begin
If you have not already done so, create a Linode account and Compute Instance. See our Getting Started with Linode and Creating a Compute Instance guides.
Follow our Setting Up and Securing a Compute Instance guide to update your system. You may also wish to set the timezone, configure your hostname, create a limited user account, and harden SSH access.
This guide is written for a non-root user. Commands that require elevated privileges are prefixed with sudo
. If you’re not familiar with the sudo
command, you can check our Users and Groups guide.
In this guide example.com
will be used as a domain name, and linode-user
as a name of non-root user. Substitute your own FQDN and username accordingly.
Install Oracle JDK 8
Add Oracle Java 8 Installer PPA repository to the system. If you are not comfortable with using 3rd-party PPA, please use instructions for manual installation of Oracle Java 8 from Java Development with WildFly on CentOS 7 guide.
sudo add-apt-repository ppa:webupd8team/java
Update package list and install Oracle JDK 8:
sudo apt-get update sudo apt-get install oracle-java8-installer
You will be asked twice on screen to agree with “Oracle Binary Code License Agreement for the Java SE Platform Products and JavaFX.” Press Ok button to agree the first time, and Yes button the second time.
Make Oracle Java default:
sudo apt-get install oracle-java8-set-default
Check installation by running:
java -version
Output should resemble the following:
java version "1.8.0_66" Java(TM) SE Runtime Environment (build 1.8.0_66-b17) Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)
Install Leiningen
Leiningen is a Clojure project-build tool. Install it system-wide:
sudo wget https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein -O /usr/local/bin/lein sudo chmod a+x /usr/local/bin/lein
To check that installation has been successful, run:
lein -v
Leiningen will update itself and then will output the version info, which should look similar to the following:
Leiningen 2.5.3 on Java 1.8.0_66 Java HotSpot(TM) 64-Bit Server VM
Create Sample Application
Now, you will create a sample Clojure web application based on Luminus framework.
In your home directory run:
lein new luminus clj-app
This will create new web application using the Luminus framework application template. It will use
immutant
as a web server, which is the default option.To check that everything went smoothly, run the newly created application in development mode:
cd clj-app lein run
Now, open http://192.51.100.1:3000/ in your browser (be sure to replace
192.51.100.1
with your Linode’s public IP), and you will see the sample application main page.Note Make sure port 3000 is open in firewall for this to work.Stop the development server by pressing Ctrl-C in console.
Install JBoss WildFly Application Server
Download and unpack the application server archive into
/opt/wildfly
directory:export VERSION=9.0.2.Final # Current stable version at the time of writing cd /opt sudo wget http://download.jboss.org/wildfly/$VERSION/wildfly-$VERSION.tar.gz sudo tar xvzf wildfly-$VERSION.tar.gz sudo mv wildfly-$VERSION wildfly #Get rid of version suffix sudo rm wildfly-$VERSION.tar.gz
Create a
wildfly
user and make him the owner of/opt/wildfly
:sudo adduser --system --group --no-create-home --home /opt/wildfly --disabled-login wildfly sudo chown wildfly -R /opt/wildfly
Copy the WildFly init script to
/etc/init.d/
and makewildfly
service start on boot:sudo cp /opt/wildfly/bin/init.d/wildfly-init-debian.sh /etc/init.d/wildfly sudo update-rc.d wildfly defaults
Start the WildFly service with:
sudo service wildfly start
Allow
linode-user
to copy war file into/opt/wildfly/standalone/deployments
, which is needed for deployment:Add
linode-user
towildfly
group:sudo usermod linode-user -a -G wildfly
Run
newgrp wildfly
aslinode-user
to log in into the new group without logging out:newgrp wildfly
Make sure
/opt/wildfly/standalone/deployments
belongs to awildfly
group and is writable by the group:sudo chown wildfly.wildfly /opt/wildfly/standalone/deployments/ sudo chmod g+w /opt/wildfly/standalone/deployments
Proxy WildFly with Nginx
Install packages for nginx:
sudo apt-get install nginx
Create file
/etc/nginx/sites-available/wildfly
with the following content:- File: /etc/nginx/sites-available/wildfly
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
upstream http_backend { server 127.0.0.1:8080; } server { listen 80; server_name example.com; location = /favicon.ico { access_log off; log_not_found off; } location / { proxy_pass http://http_backend; proxy_http_version 1.1; proxy_set_header Connection ""; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; access_log /var/log/nginx/wildfly.access.log; error_log /var/log/nginx/wildfly.error.log; } }
Do not forget to substitute
example.com
with your Linode domain name or public IP address.Enable your newly created
wildfly
site and remove thedefault
site to avoid conflicts:sudo ln -s /etc/nginx/sites-available/wildfly /etc/nginx/sites-enabled sudo rm /etc/nginx/sites-enabled/default
Restart nginx for changes to take effect:
sudo service nginx restart
Deploy Sample Application with Immutant
To deploy Clojure application with WildFly you will need to install the Immutant leiningen plugin and configure it for the deployment.
Open
project.clj
file inclj-app
directory and add[lein-immutant "2.1.0"]
to the:plugins
section of configuration:- File: /home/linode-user/clj-app/project.clj
1 2
:plugins [[lein-environ "1.0.1"] [lein-immutant "2.1.0"]]
In
project.clj
and after:plugins
, add a new:immutant
section with the following content :- File: /home/linode-user/clj-app/project.clj
1 2 3 4 5 6 7
:immutant { :war { :name "ROOT" :destination "/opt/wildfly/standalone/deployments" :context-path "/" } }
This sets three parameters for Immutant installation:
- The destination folder for the WAR file
- The context path
- The WAR file name, which should be ROOT when the context path is
/
.
Switch to the
clj-app
directory and deploy the application with:cd ~/clj-app lein immutant war
At this point, you should be able to open your Linode’s domain or IP address in a browser and see the sample application’s main page.
More Information
You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.
This page was originally published on