If you are going to start JAVA Spring development or want to run the JAVA spring application on a production server then you must need to prepare the server so it can run your JAVA Spring application. There are several articles online but I am writing the easy way so you can just copy and paste the command and get your server ready for the JAVA Spring application.
First, you have to run the command below to update the ubuntu package
sudo apt update
Then add the repository, Just follow the command bellow
Step 1 – Install Oracle Java 8 on Ubuntu
sudo add-apt-repository ppa:webupd8team/java sudo apt-get update sudo apt-get install oracle-java8-installer
Step 2 – Verify Java Installation
sudo apt-get install oracle-java8-set-default
Check Java Version
It will show you result like bellow
java version “1.8.0_201” .
Java(TM) SE Runtime Environment (build 1.8.0_201-b09) .
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)
If you are still confused you can check this video
Step 3 – Create Tomcat User
wget http://www-us.apache.org/dist/tomcat/tomcat-9/v9.0.19/bin/apache-tomcat-9.0.19.tar.gz . tar xzf apache-tomcat-9.0.19.tar.gz . sudo mv apache-tomcat-9.0.19 /usr/local/apache-tomcat9
Step 4 – Configure Environment Variables
echo "export CATALINA_HOME="/usr/local/apache-tomcat9"" >> ~/.bashrc . echo "export JAVA_HOME="/usr/lib/jvm/java-11-oracle"" >> ~/.bashrc . echo "export JRE_HOME="/usr/lib/jvm/java-11-oracle"" >> ~/.bashrc . source ~/.bashrc
Step 5 – Setup Tomcat User Accounts
Go to the tomcat install directory
/usr/local/apache-tomcat9 and then edit tomcat-users.xml according to the rule bellow
<role rolename="manager-gui" /> <user username="manager" password="_SECRET_PASSWORD_" roles="manager-gui" /> <!-- user admin can access manager and admin section both --> <role rolename="admin-gui" /> <user username="admin" password="sa123" roles="manager-gui,admin-gui" />
Step 6 – Starting Tomcat Service
cd /usr/local/apache-tomcat9 chmod +x ./bin/startup.sh ./bin/startup.sh
Sample output will be as like bellow
Using CATALINA_BASE: /usr/local/apache-tomcat9 Using CATALINA_HOME: /usr/local/apache-tomcat9 Using CATALINA_TMPDIR: /usr/local/apache-tomcat9/temp Using JRE_HOME: /usr/lib/jvm/java-11-oracle Using CLASSPATH: /usr/local/apache-tomcat9/bin/bootstrap.jar:/usr/local/apache-tomcat9/bin/tomcat-juli.jar Tomcat started.
If there any problem it may be your JAVA version, which you can resolve by doing the following guideline
And then run the following command
Following the process, you can easily install the Tomcat server on Ubuntu for JAVA Spring. You can also see our other articles to learn file_get_contents was found in the file – A complete solution to overcome it
We hope this article will help you. If you like this article please like our Facebook Page to stay connected.