DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • JMeter Plugin HTTP Simple Table Server (STS) In-Depth
  • JVM Tuning Using jcmd
  • Cookies Revisited: A Networking Solution for Third-Party Cookies
  • Integrating Redis With Message Brokers

Trending

  • How the Go Runtime Preempts Goroutines for Efficient Concurrency
  • Building Enterprise-Ready Landing Zones: Beyond the Initial Setup
  • Integration Isn’t a Task — It’s an Architectural Discipline
  • A Simple, Convenience Package for the Azure Cosmos DB Go SDK
  1. DZone
  2. Coding
  3. Languages
  4. Deploying Web Application Using Vagrant

Deploying Web Application Using Vagrant

By 
Arpit Aggarwal user avatar
Arpit Aggarwal
·
Jun. 04, 15 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
29.1K Views

Join the DZone community and get the full member experience.

Join For Free

In this article, we will deploy a Spring web application in Tomcat 7 on Ubuntu 12.04 VM, created and provisioned using Vagrant. As an initial step,  Download Vagrant  specific to your operating system and install it in your machine.


Then create a folder on a drive, for me its "workspace" created on D drive (D:/workspace).


Now, open a command prompt and go to "workspace" folder and execute below command to clone the GIT repository on local drive:

git clone https://github.com/arpitaggarwal/hello-spring.git

Once clone completed, execute command:


vagrant init


Above command will create a Vagrant file (Vagrantfile), replace the content with below:


Vagrant.configure(2) do |config|
  # A standard Ubuntu 12.04 LTS 32-bit box
  # For more boxes, you can look at https://atlas.hashicorp.com/boxes/search
  config.vm.box = "hashicorp/precise32"
  config.vm.provision "shell", path: "vagrant_provision.sh"
  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  config.vm.network "private_network", ip: "192.168.33.10"
end


Then create a vagrant_provision.sh file under same directory and copy below contents to the file:


#!/usr/bin/env bash
sudo apt-get update
echo "Installing Apache.."
sudo apt-get install -y apache2
echo "Installing Tomcat.."
sudo apt-get install -y tomcat7
echo "Installing Tomcat7 docs.."
sudo apt-get install -y tomcat7-docs
echo "Installing Tomcat7 administration webapps.."
sudo apt-get install -y tomcat7-admin
echo "Installing Tomcat7 examples webapps.."
sudo apt-get install tomcat7-examples
echo "Installing Git.."
sudo apt-get install -y git
echo "Installing Maven.."
sudo apt-get install -y maven
echo "Installing Java 7.."
sudo apt-get install -y software-properties-common python-software-properties
echo oracle-java7-installer shared/accepted-oracle-license-v1-1 select true | sudo /usr/bin/debconf-set-selections
sudo add-apt-repository ppa:webupd8team/java -y
sudo apt-get update
sudo apt-get install oracle-java7-installer
echo "Setting environment variables for Java 7.."
sudo apt-get install -y oracle-java7-set-default


Then execute command:


vagrant up


Above command will make our VM up and running, also make an instance of Apache and Tomcat running (which we mentioned in vagrant_provison.sh).


To check if Apache is running, hit url : http://192.168.33.10 and to check if Tomcat is running, hit url : http://192.168.33.10:8080


Now, we will log into our newly created VM and build our project (cloned from Git) and copy it to the Tomcat deployment directory. So, we will first open our VM terminal executing below command:


vagrant ssh

Now we will first check where our project is, so execute below command:


cd /
ls


Now we can see folder name "vagrant", this is the folder which is linked to our host machine and going inside we will see our cloned project. Next we will go inside and build it executing below commands:


cd vagrant
cd hello-spring
mvn clean install


It will generate a target folder and our .war file inside it, now we will copy this .war to Tomcat 7 deployment directory after coming back to root directory, using command below:


cd /
sudo cp /vagrant/hello-spring/target/hello-spring.war /var/lib/tomcat7/webapps/


Now, our application is copied to tomcat deployment directory and we are ready to hit the url and see our application running, but before that we have to change the Java version for tomcat, as our application is compiled using 1.7 and tomcat is using 1.6. It's easy, just go to the root directory and execute below commands:


cd etc/default 
nano tomcat7


And search for JAVA_HOME, uncomment it and edit as below:


JAVA_HOME=/usr/lib/jvm/java-7-oracle

Now, just restart the Tomcat instance, using command below:


service tomcat7 restart

Open the url : http://192.168.33.10:8080/hello-spring in host browser and we will see the welcome page of our Spring application.

Web application Command (computing) Apache Tomcat

Opinions expressed by DZone contributors are their own.

Related

  • JMeter Plugin HTTP Simple Table Server (STS) In-Depth
  • JVM Tuning Using jcmd
  • Cookies Revisited: A Networking Solution for Third-Party Cookies
  • Integrating Redis With Message Brokers

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!