views:

28

answers:

1

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).

A: 

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:

getServletContext().getRealPath( "images" )

Which gives:

/home/tomcat/apache-tomcat-6.0.26/webapps/mywebapp/download

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?

NoozNooz42
Yes, that's what I was looking for! The reason I want to spawn a new process is rather specific: this new process will itself be a "remote process server". It will be there to allow me to launch new processes without hitting the fork() resource allocation problem and getting oom errors, especially on Linux with memory-overcommit to false. See http://mail.openjdk.java.net/pipermail/core-libs-dev/2009-May/001644.html for a better explanation. So my "remote server" will have a small maximum heap space, and forking it won't mean allocating lot of resources as is the case with my main servlet.
alci