如何在java中嵌入tomcat

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24915333/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 15:36:23  来源:igfitidea点击:

How to Embed tomcat in java

javatomcat

提问by cJ_

I am trying to embed tomcat in java application. I searched the google but no luck. i was not able to find good tutorial. is there any complete tutorials or api docs for embedding tomcat. this question might be duplicate of another question. but it seems old. I read that tomcat 7 api over tomcat 6 is lot improved. so i considered it as old. Any links for tutorials is appreciated.

我正在尝试将 tomcat 嵌入到 Java 应用程序中。我搜索了谷歌,但没有运气。我找不到好的教程。是否有用于嵌入 tomcat 的完整教程或 api 文档。这个问题可能与另一个问题重复。但它看起来很旧。我读到 tomcat 7 api 比 tomcat 6 有很大改进。所以我认为它是旧的。任何教程链接表示赞赏。

回答by radai

there's a more recent tutorial about embedding tomcat 8 here.

有一个更近的有关嵌入的Tomcat 8教程在这里

the gist of it:

它的要点:

public static void main(String[] args) throws Exception {
    Tomcat tomcat = new Tomcat();
    tomcat.setPort(8080);

    //actually deploy stuff on your tomcat by defining contexts          

    tomcat.start();
    tomcat.getServer().await();
}