-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Tomcat #27
Comments
This is a working example: https://vaadin.com/forum/t/vaadin-10-tomcat-embedded/157777 Some shortcomings - needs investigating:
Otherwise it seems to be working. Things to test:
|
Push works. Only the following dependencies are necessary: <dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>10.1.28</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-websocket</artifactId>
<version>10.1.28</version>
</dependency> The app prints this to stderr but otherwise works:
We can either manually remove the JSP servlet somehow (since it's unnecessary), or just add necessary jar to the classpath ( both options are acceptable)., |
Adding servlet such as @WebServlet(urlPatterns = {"/*"})
public class MyServlet extends VaadinServlet {
} removes the need for having to register the servlet manually: tomcat.addServlet("", "", VaadinServlet.class.getName());
ctx.addServletMappingDecoded("/*", ""); |
The |
Sounds like tomcat only performs servlet scanning of classes located in the
The code is something like: File additionWebInfClasses = new File("target/classes").getAbsoluteFile();
if (additionWebInfClasses.exists()) {
WebResourceRoot resources = new StandardRoot(ctx);
resources.addPreResources(new DirResourceSet(resources, "/WEB-INF/classes",
additionWebInfClasses.getAbsolutePath(), "/"));
ctx.setResources(resources);
}
File productionJar = new File("libs/vaadin-boot-example-maven-1.0-SNAPSHOT.jar").getAbsoluteFile();
if (productionJar.exists()) {
System.out.println("PRODUCTION!!!!! " +productionJar);
WebResourceRoot resources = new StandardRoot(ctx);
resources.addPreResources(new JarResourceSet(resources, "/WEB-INF/classes",
productionJar.getAbsolutePath(), "/"));
ctx.setResources(resources);
} |
Yup: manually registering the Vaadin servlet is easier than adding classes to virtual WAR; this code works both in dev mode and in production: tomcat.addServlet("", "", VaadinServlet.class.getName());
ctx.addServletMappingDecoded("/*", ""); Adding back. What's strange is that Tomcat is apparently capable of discovering Vaadin's |
Uh-oh - we might need to enable the classpath scanning after all, otherwise |
Initial implementation is ready.
This means that the app structure is a bit different from when using the Jetty launcher: Jetty launcher expects webapp on classpath, in the An alternative would be to continue using the webapp-in-resources approach identical to Jetty, and then unpack the webapp folder to a temp folder when running in production mode (since Tomcat can't serve static resources from a jar file... or can it? Maybe we can populate the virtual WAR file by the jar file contents - explore). |
* #27 add the 'vaadin-boot-tomcat' module * #27 initial impl of VaadinBoot for Tomcat * #27 initial impl of VaadinBoot for Tomcat * #27 Add testapp-tomcat * #27 initial impl of VaadinBoot for Tomcat * #27 Tomcat VaadinBoot: fix basedir configuration * #27 Tomcat VaadinBoot: fix basedir configuration * #27 Tomcat VaadinBoot: enable classpath scanning * #27 minor build.gradle cleanup * #27 honor VaadinBoot.contextRoot setting * #27 fix production mode * #27 minor * #27 minor * #27 extract common bits to the 'common' project * #27 extract common bits to the 'common' project * #27 javadoc * #27 minor * #27 documentation * #27 documentation * #27 documentation * #27 TomcatWebServer: use standard JVM class-loading order * #27 TomcatWebServer: refactoring * #27 TomcatTest refactoring * #27 JettyTest refactoring * #27 WebServer: docs * #27 fix compat with jdk 17 * #27 testapp-kotlin: more thorough tests * #27 configure Tomcat to serve static files from classpath://webapp * Fix tests on Windows * Fix tests on Windows * #27 Env: implement Env.findResourcesJarOrFolder() to also support classpath URLs pointing into JAR files * #27 minor * readme * readme * readme * #27 common: add tests * #27 refactor existing Jetty VaadinBoot on top of common VaadinBootBase * #27 minor * #27 todo * #27 fix flaky tests * #27 fix flaky tests * #27 TomcatWebServer: detect main jar via the 'webapp' resource scan * #27 Add testapp-kotlin-tomcat * #27 TomcatWebServer: minor refactoring * #27 v bump to 13.0-SNAPSHOT * #27 improve detection of app's class folder * #27 enable logging
Support for Tomcat will be added in Vaadin-Boot 13.0 |
Starting an embedded Tomcat looks pretty easy too: https://devcenter.heroku.com/articles/create-a-java-web-application-using-embedded-tomcat
Perhaps I could add a way for the user to choose between Jetty and Tomcat.
The text was updated successfully, but these errors were encountered: