Wednesday, July 31, 2019

Deploy WAR File Into Tomcat Server of VirtualBox

Installing Tomcat 7

Step 1: Create the Tomcat Folder
Logged in as root, within the opt folder make a directory called tomcat and cdinto that folder after completion.
mkdir /opt/tomcat
cd /opt/tomcat
 Step 2: Install Tomcat Through Wget
Click this link to the Apache Tomcat 7 Download site. Place your cursor under7.0.90 Binary Distributions, right click on the tar.gz file and select Copy Link Address (as shown in the picture below).  At the time of this article Tomcat 7 is the newest version but feel free to pick whatever version is more up-to-date.
Next, from your server, use wget command to download the tar to  the tomcat folder from the URL you copied in the previous step:
wget http://www.trieuvan.com/apache/tomcat/tomcat-7/v7.0.90/bin/apache-tomcat-7.0.90.tar.gz
After the download completes, decompress the file in your Tomcat folder:
tar xvzf apache-tomcat-7.0.90.tar.gz
You will end up with a file called apache-tomcat-7.0.90.
Step 3: Install Java
Before you can use Tomcat, you’ll have to install the Java Development Kit (JDK). Beforehand, check to see if Java is installed:
java -version
If that command returns the following message then Java has yet to be installed:
The program 'java' can be found in the following packages:
To install Java, simply run the following command (and at the prompt enter Y to continue:
apt-get install default-jdk

Step 4: Configure .bashrc file
Set the environment variables in .bashrc with the following command:
vim ~/.bashrc
Add this information to the end of the file:
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64
export CATALINA_HOME=/opt/tomcat/apache-tomcat-7.0.90
Save your edits and exit from the .bashrc file, then run the following command to register the changes:
. ~/.bashrc

Step 5: Test Run
Tomcat and Java should now be installed and configured on your server. To activate Tomcat, run the following script:
$CATALINA_HOME/bin/startup.sh
You should get a result similar to:
Using CATALINA_BASE: /opt/tomcat
Using CATALINA_HOME: /opt/tomcat
Using CATALINA_TMPDIR: /opt/tomcat/temp
Using JRE_HOME: /usr/lib/jvm/java-7-openjdk-amd64/
Using CLASSPATH: /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
Tomcat started.

To verify that Tomcat is working by visiting the IP address of your server:8080 in a web browser. For example http://127.0.0.1:8080.
Tomcat 7.0.90 Test Page

To stop tomcat:
$CATALINA_HOME/bin/shutdown.sh

Share WAR Folders between Host and Guest OS in VirtualBox

You can do this by going to Devices again and clicking on Shared Folders – Shared Folders Settings.
Now click on the Add New Shared Folder button on the right.
share files virtualbox
In the Folder Path box, click the down arrow and then click Other. Browse to the folder on the host OS that you would like to share with the guest OS. In the Folder Name box, give your share a name. You can choose to make it read-only, auto-mount the folder after restarts, and make the shared folder permanent.
Click OK and the new shared folder will show up under Machine Folders if you chose to make it Permanent, otherwise it will show under Transient Folders.
share folders virtualbox
Now click OK to close the Shared Folders dialog. You have to do one more thing in order to be able to actually access the folder on the host OS. Depending on whether the guest OS is running Windows or Linux (Ubuntu, etc), the method is different.
To mount a shared folder in a Linux Guest OS such as Ubuntu, type in the following command in terminal:

mount -t vboxsf [-o OPTIONS] sharename mountpoint

Replace sharename with the name of the share and mountpoint with the path where you want the share to be mounted (i.e. /mnt/share, /media/shared).
NOTE: if you get any fs (file system) error. then execute below commands

sudo apt-get install virtualbox-guest-utils
If problem remains then install corresponding file system support as like as:
sudo apt install nfs-commonsudo apt install cifs-utils

Deploy WAR by Copy

Open terminal as a root user


sudo su
Copy WAR file to inside of tomcat webapps folder
cp /mnt/shared/project.war /opt/tomcat/apache-tomcat-7.0.90/webapps/
Then start tomcat server if required. If you need to see the log of your project:
tail -f /opt/tomcat/apache-tomcat-7.0.90/logs/project.log

No comments:

Post a Comment