The reason to do that is because I want to use Runtime.exec() using the same classpath as my servlet.
The class I want to run is within WEB-INF/classes/my/package/.
So I want to build a cmdarray as String[] {“java”,”-cp”, my_servlet_classpatch, “my.package.myclass”}
I just can’t find a way to get my running servlet classpath.
NB: This has to work in Tomcat or Jetty (or any decent servlet container).
Would
getServletContext().getRealPath(...)be what you’re looking for?For example I need to do some image processing if the webapp is on Linux and if the ImageMagick tools are available (and, no, I don’t want to use the Java ImageMagick wrapper). My webapp has got an “images” repository into which all my images are present. I can get the actual deployed directory by issuing a:
Which gives:
Note that in your case I’m not sure you need this: do you really want to spawn a new Java process using Runtime.exec?