Tutorial : build full Java server with Tomcat8 at public IP with Raspberry Pi

It can not be truly easier to build your own Java server with Tomcat and expose it to public IP address.
You will get facility to host you Java apps with zero cost for hosting plus users will able to use it at public IP. Ideal for hobby-coders.

I will use Raspberry Pi 2 Model B 1GB. Whole process will take less than 20 minutes.

 

Step 1 : obviously – get Raspberry 🙂

Step 2 : install its default OS Raspbian – download image at https://www.raspberrypi.org/downloads/raspbian/

Step 3 : create SD card using Win32Diskimager – get it at https://sourceforge.net/projects/win32diskimager/

Step 4 : insert SD card into Raspberry (power off)

Step 5 : connect Raspberry to power, TV (or monitor), USB mouse and LAN

Step 6 : it will boot into Raspbian

Step 7 : at your PC – download putty at http://www.putty.org/

Step 8 : connect to your router and get IP of your rapsberry (in my case 192.168.1.103)

Step 9 : run putty.exe and insert this IP as Host Name – press Open to estabilish ssh connection

Step 10 : login into rapsberry : user name=pi, password=raspberry

Step 11 : trigger system update :
sudo apt-get update

Step 12 : confirm java version
java -version
output :
java version "1.8.0_65"
Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
Java HotSpot(TM) Client VM (build 25.65-b01, mixed mode)

Step 13 : install Tomcat8
sudo apt-get install Tomcat8
sudo apt-get install tomcat8-admin

Step 14 : after installation Tomcat is running at port 8080, open browser at access IP:8080 (example 192.168.1.103:8080)

Step 15 : configure Tomcat – add user to access app-management
sudo service tomcat8 stop
cd /var/lib/tomcat8/conf
sudo nano tomcat-users.xml

add below 2 lines after <tomcat-users>
<role rolename=“manager-gui“/>
<user username=“anyuser“ password=“anypsw“ roles=“manager-gui“/>

Step 16 : start Tomcat
sudo service tomcat8 start

Step 17 : access Tomcat´s console again at http://192.168.1.103:8080/manager/html (replace IP yours)
for login use credentials you configured in step 15 (anyuser/anypsw)
now you can see typical Tomcat´s Application console. Cool.

Step 18 : deploy your Java project compiled into war file
scroll down to „WAR file to deploy“, browse war file and press Deploy.

Step 19 : once deployed, you will see your app in list of apps with status Running, click to app name and Wualla – app is up and running at your Rapsberry. Anyway – only accessible at localhost.

Step 20 : expose your app server using public IP.
Note : if you dont have public IP already – please consult your internet provider how to get it.
Open your router console – go to Port Forwarding and add your Rapsberry´s IP and Tomcat default port 8080.

Step 21 : test it
in browser open your public IP with port 8080 – you should see your Tomcat and app up and running !

Napsat komentář