I have a server
module which depends on a web
modules:
<dependency> <groupId>org.ema.server</groupId> <artifactId>web</artifactId> <version>0.0.1-SNAPSHOT</version> <type>war</type> </dependency>
which is getting re-packaged with the spring-boot-maven-plugin
in order to get a standalone:
<plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <fork>true</fork> <mainClass>org.ema.server.Server</mainClass> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin>
Everything is working so far. The web
module is getting included into the final jar as BOOT-INF/lib/web-0.0.1-SNAPSHOT.war
.
I know Spring allows one to load additional war files for Tomcat at runtime but it appears that such a war
file must either be located somewhere in the file system or I am doing it wrong.
The question is how I can keep the standalone feeling but still be able to add war
files into my final standalone jar
and deploy them to the built-in Tomcat?
Below is the code that shows how one could potentially do this but I am not sure if it can be done the way I require it:
@Bean public EmbeddedServletContainerFactory servletContainerFactory() { LOGGER.info("Adding web app"); return new TomcatEmbeddedServletContainerFactory() { @Override protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer(Tomcat tomcat) { // Ignore that since it's not working anyway. String resourcePath = getClass().getResource("/../lib/web-0.0.1-SNAPSHOT.war").getPath().toString(); try { tomcat.addWebapp("/web", resourcePath); } catch (ServletException ex) { throw new IllegalStateException("Failed to add webapp", ex); } return super.getTomcatEmbeddedServletContainer(tomcat); } }; }
0 comments:
Post a Comment