Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Embed tomcat in java [closed]

Tags:

java

tomcat

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.

like image 917
cJ_ Avatar asked Jul 23 '14 15:07

cJ_


People also ask

Can we disable Tomcat in spring boot?

If we want to exclude tomcat from spring boot, we don't need to do much, we just need to add one additional block(<exclusions>) to the Spring Boot dependency. <exclusions> tag is used to make us sure that given server/artifactId is being removed at the time of build.

Is Tomcat embedded?

An embedded Tomcat server consists of a single Java web application along with a full Tomcat server distribution, packaged together and compressed into a single JAR, WAR or ZIP file.


1 Answers

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

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();
}
like image 95
radai Avatar answered Nov 06 '22 17:11

radai