How to Embed Tomcat within Maven Project – Run Tomcat with Maven

Tomcat is a developers choice container. The most popular and loved Java container that everyone loves because of its simplicity and speed. This can be attributed to the ease of installation and configuration while running a tomcat server. Once the server is installed, it is like piece of cake running it through Eclipse or as a windows service.

Wouldn’t it be great to use tomcat without installing tomcat all together? This is exactly what you can achieve thanks to Maven. Maven has a wonderful plugin tomcat7-maven-plugin that we can use to embed tomcat within our Java web application. The idea is to create standalone web project that can start tomcat server and run on its own. All we need to do is the add following maven plugin in your pom.xml plugins list.


And once this is done all we have to do is to clean build the project using maven.

mvn clean install

And then running maven tomcat7:run goal which will download the dependencies and trigger the tomcat7-maven-plugin.

mvn tomcat7:run

And that’s it. Once we fire this tomcat7:run goal, maven will start its magic. First all related dependencies will be downloaded, the webapp will be compiled and packaged and then tomcat7 maven plugin will deploy the webapp and start the embedded server.

You will have something similar to following.

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building HelloWorld Maven Webapp 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] >>> tomcat7-maven-plugin:2.2:run (default-cli) > process-classes @ HelloWorld >>>
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ HelloWorld ---
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ HelloWorld ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] <<< tomcat7-maven-plugin:2.2:run (default-cli) < process-classes @ HelloWorld <<<
[INFO] 
[INFO] --- tomcat7-maven-plugin:2.2:run (default-cli) @ HelloWorld ---
[INFO] Running war on http://localhost:8080/HelloWorld
[INFO] Using existing Tomcat server configuration at C:\workspace\test\HelloWorld\target\tomcat
[INFO] create webapp with contextPath: /HelloWorld
Jun 15, 2016 3:10:40 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Jun 15, 2016 3:10:40 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Tomcat
Jun 15, 2016 3:10:40 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.47
Jun 15, 2016 3:10:52 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]

And then just open your web applications link http://localhost:8080/ in your favorite browser.

embedded-tomcat-maven-plugin

Change the Port number

By default the embedded tomcat will try to initialize at port 8080. We can change this by passing port number in configuration.


Using different context path

Also, by default the web context for the application will be our maven projects artifact id. We can change the path or web context by setting new path in configuration.


Following is the sample pom.xml for reference.

pom.xml

The post How to Embed Tomcat within Maven Project – Run Tomcat with Maven appeared first on ViralPatel.net.



via ViralPatel.net http://ift.tt/1VYXqsm

IObit Malware Fighter 4.2.0.2425

http://ift.tt/1T9jcJu IObit Malware Fighter is an advanced malware & spyware removal utility that detects, removes the deepest infections, and protects your PC from various potential spyware, adware, trojans, keyloggers, bots, worms, and hijackers. The app utilises a ‘Dual-Core’ engine and heuristic malware detection. With these tools IObit Malware Fighter is able to...


via FileHippo.com http://ift.tt/1oJJhlz [[ We are also giving web service. Email:wasim.akh2@gmail.com]]

WinUtilities 13.0

http://cache.filehippo.com/img/ex/3226__winutilities.png WinUtilities is a selection of professional tools, which are designed to help you optimize your computer's system performance by performing tasks such as removing unnecessary files and fixing broken shortcuts. KEY FEATURES INCLUDE With WinUtilities you can delete your application and Internet history. You can find and remove invalid registry e...


via FileHippo.com http://ift.tt/UMDZGp [[ We are also giving web service. Email:wasim.akh2@gmail.com]]

DVD FAB 9.3.0.4

http://ift.tt/1xhCuxi DVDFab 9 is a DVD/Blu-ray/video processing application. The application allows you to copy any DVD/Blu-ray disc to a computer HDD and then burn it to blank media, or convert it to a variety of video files to be played on either a computer, portable devices or other compatible display. DVDFab 9 is an integrated shareware package that includes DVDF...


via FileHippo.com http://ift.tt/12qJHBU [[ We are also giving web service. Email:wasim.akh2@gmail.com]]

Miranda 0.10.53

http://ift.tt/Qh2rWg Miranda IM is a multi-protocol instant messenger client for Windows. Miranda IM uses very little memory and is extremely fast. It requires no installation and can be fitted on a single floppy disc. Its powerful plugin system makes Miranda IM very flexible. Only the most basic features are built in, but there are currently more than 350 free plugins...


via FileHippo.com http://ift.tt/12XNPGD [[ We are also giving web service. Email:wasim.akh2@gmail.com]]

AdwCleaner 5.200

http://ift.tt/1A2cpYl AdwCleaner is an application that searches for and deletes Adware, Toolbars, Potentially Unwanted Programs (PUP) and browser Hijackers from your computer. By using AdwCleaner you will be able to remove numerous types of unwanted programs. This in turn will give you a more streamlined PC and a better user experience whilst browsing the web. Key Fe...


via FileHippo.com http://ift.tt/15LaYR1 [[ We are also giving web service. Email:wasim.akh2@gmail.com]]

Rem-VBSworm 8.0.0

http://ift.tt/1Oneh6v Rem-VBSworm (Remediate VBS Worm) is an anti-malware tool that has been designed to detect and then remove different kinds of VBS infections, such as Bladabindi, Excedow, Jenxcus, and Houdini/Dinihu. It can also detect and protect against WSH (Windows Script Host) malware and autorun worms. Running Rem-VBSworm is a simple process; just insert...


via FileHippo.com http://ift.tt/1UNgerU [[ We are also giving web service. Email:wasim.akh2@gmail.com]]

Windows 11 Insider Preview Build 29560.1000 Released to New Canary Channel

UPDATE: Windows 11 Insider Preview build 29560.1000 released to the new Canary channel. Windows Insiders on the refreshed Canary Channel wil...