executable-embeded-tomcat-sample
executable-embeded-tomcat-sample copied to clipboard
executable-embeded-tomcat-sample, support traditional web.xml.
executable-embeded-tomcat-sample
Features
- Support web.xml
spring boot is a great project, but it don't support web.xml. This project support traditional web.xml.
- Support Fat jar
By spring-boot-maven-plugin, the project can be packaged into an executable jar.
You can also use maven-assembly-plugin/jar-with-dependencies, but spring-boot-maven-plugin is a better choice.
- Run in IDE
Sample
Run main class io.github.hengyunabc.Main in your IDE, or
mvn clean package
java -jar target/executable-embeded-tomcat-sample-0.0.1-SNAPSHOT.jar
Open the following link in your browser:
http://localhost:8080/test.jsp
http://localhost:8080/hello
http://localhost:8080/annotation
How to migrate from a webapp project
It is very simple.
-
add embeded tomcat maven dependencies into your pom.xml
-
move
src/main/webapp/WEB-INFtosrc/main/resources/WEB-INF, move all files undersrc/main/webapptosrc/main/META-INF/resources.
according to servlet 3.0, ServletContext can get static content from
META-INF/resource.
- add a main class, start your embeded tomcat.
Others
http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/basic_app_embedded_tomcat/basic_app-tomcat-embedded.html
A sample from oracle, but it do not support web.xml, and do not support run in IDE.
https://github.com/kui/executable-war-sample
Another sample, it has security problems. people can access your .class file through http!!
License
Apache License V2