I am trying to migrate a Jersey Tomcat project into Embedded Tomcat with the Shadow Plugin to simplify deployment.
I based my changes on this tutorial . It is for Spring, so I skipped the Spring specific parts.
The main changes are the addition to the Embedded Tomcat and Shadow Plugin dependencies to build.gradle.kts ...
plugins {
id("java")
id("maven-publish")
id("application")
id("com.github.johnrengelman.shadow") version "7.1.0"
}
dependencies {
.
.
.
implementation("org.apache.tomcat.embed:tomcat-embed-jasper:10.0.12")
}
... and the creation of the Main class as follows:
import org.apache.catalina.startup.Tomcat;
import java.io.File;
import java.io.IOException;
public class Main {
private static final int PORT = 8080;
public static void main(String[] args) throws Exception {
String appBase = ".";
Tomcat tomcat = new Tomcat();
tomcat.setBaseDir(createTempDir());
tomcat.setPort(PORT);
tomcat.getHost().setAppBase(appBase);
tomcat.addWebapp("", appBase);
tomcat.start();
tomcat.getServer().await();
}
// based on AbstractEmbeddedServletContainerFactory
private static String createTempDir() {
try {
File tempDir = File.createTempFile("tomcat.", "." + PORT);
tempDir.delete();
tempDir.mkdir();
tempDir.deleteOnExit();
return tempDir.getAbsolutePath();
} catch (IOException ex) {
throw new RuntimeException(
"Unable to create tempDir. java.io.tmpdir is set to " + System.getProperty("java.io.tmpdir"),
ex
);
}
}
}
When I try to run or debug this either from the cli or from IntelliJ I get no build errors and IntelliJ reports that the app is running. However, I can't reach any of the endpoints of the server.
I do get this warning:
Dec 08, 2021 6:57:15 PM org.apache.catalina.startup.ContextConfig getDefaultWebXmlFragment
INFO: No global web.xml found
The project does have a global web.xml located in src/main/webapp/WEB-INF/web.xml
, but it doesn't seem to be recognized.
It seems like Shadow is not loading my code into the Tomcat server. Is there something missing to link Shadow Plugin > Embedded Tomcat > My Jersey project?