简体   繁体   中英

Tomcat - Running external JAR/WAR

So I have a little Tomcat web app I am running, with the following structure :

  • Main Servlet
  • Class for Job A
  • Class for Job B
  • Class for Job C
  • Tons of classes used for the various jobs executions

The webapp is compiled & deployed via ant. At the moment, I get a nice Project.war with all classes.

Basically, the main servlet works as a dispatcher. Depending of the webrequest received, it launches either Job A, B or C in a new thread.

I want to improve my application so that I can redeploy the class for Job A/B/C without affecting running processes. Here's how I am conceptualizing it :

  • I deploy the main servlet, used as a dispatcher.
  • I deploy A.war, B.war, C.war
  • I run B.war
  • I redeploy A.war, B.war is still running
  • I run A.war
  • B.war is done, its output is sent back via the main servlet.

To be brutally honest, I have no idea on where to start or where to look at. I thought about using a ProcessBuilder and executing the jar/war in command line, but it feels like the most unsafe thing to do.

Any input is appreciated.

Thank you !

I believe you need a modular application where you have multiple plugins (Jobs in your case) which can be loaded or unloaded when you want, and to be used once available. Check this stackoverflow question it can give you a little help.

But for simplicity, in a previous job we needed something acts like OSGI without using OSGI, we built API using serviceLoader and created an interface for our module (in your case job) each jar will have a class which will implement the interface. And once the job is needed you can call for it from the service loader if it exist you can use it, if not throw some error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM