Embedded Java EE development with embeded Tomcat-start Tomcat

Source: Internet
Author: User

I studied online yesterday about embedding Tomcat in the main program, rather than running a Web project copy into Tomcat as before. The reason for this is that because the project is deployed to the client side, it needs to be updated manually when the update is made, then copy the code to tomcat and then run it. With embeded Tomcat, you can separate the project from Tomcat and, when updating, use a custom program to automate the update, and then start Tomcat (or other Java EE containers) to run the project before the update is complete.

The ultimate effect of this is to modify the way the project is run. The original operation was a Tomcat-centric, Tomcat-initiated and terminated project, which is now centered on our startup program and is responsible for starting and terminating the project. Just like the popular CS program, there are separate startup scripts, pre-initialization of the environment at startup, updates and other operations, and the final project starts after completion.

This article mainly explains how to use embeded tomcat to start and terminate in code. The general articles on the Internet are tomca5.x to do, the use of the latest TOMCAT7, because TOMCAT7 for embeded development, a separate org.apache.tomcat.embed package to carry out independent embed development. The following is the appropriate MAVEN package

0102030405060708091011121314151617181920 <dependency>            <groupId>org.apache.tomcat.embed</groupId>            <artifactId>tomcat-embed-core</artifactId>            <version>7.0.2</version>        </dependency>        <dependency>            <groupId>org.apache.tomcat</groupId>            <artifactId>tomcat-util</artifactId>            <version>7.0.2</version>        </dependency>        <dependency>            <groupId>org.apache.tomcat.embed</groupId>            <artifactId>tomcat-embed-jasper</artifactId>            <version>7.0.2</version>        </dependency>        <dependency>            <groupId>org.apache.tomcat.embed</groupId>            <artifactId>tomcat-embed-logging-juli</artifactId>            <version>7.0.2</version>        </dependency>

The core package in the embed package is used, as well as the Jasper package for compiling the JSP, followed by the tool class and the Logging-juli package for the play record. Start writing code:

1234567 //设置工作目录        String catalina_home = "d:/";        Tomcat tomcat = new Tomcat();        tomcat.setHostname("localhost");        tomcat.setPort(startPort);        //设置工作目录,其实没什么用,tomcat需要使用这个目录进行写一些东西, Courier, monospace!important; Font-weight:normal!important; Font-style:normal!important

Embedded Java EE development with embeded Tomcat-start Tomcat

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.