You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Wojciech Ciesielski <wo...@softwaremind.pl> on 2006/02/10 17:25:50 UTC

Getting directory in which app is deployed

Hi there,

I have one problem... We have to execute external Java process from JAR archive included in our web application directory. The problem is, that all system dependant functions are relative to tomcat home directory. And - when our application is deployed outside tomcat directory via server.xml context definition - we cannot find a way to get path to our web directory...

I am not sure if I am expressing myself clear, so example...

I have web app with structure:

someDir/web:
  WEB-INF
  META-INF
  dirWithArchive
    externalProgram.jar
  ...

which is deployed OUTSIDE tomcat. I need to execute such code:

Process = new ProcessBuilder("java -jar some/path/to/someDir/web/dirWithArchive/externalProgram.jar".split("\\s+").start();

from within struts action or struts plugin. HOW can I find a path without specifying it manualy (it's problematic because of different environments we deploy our application to).

TIA

Wojciech Ciesielski
Software Mind | Where Quality Meets the Future 
 
mailto:woci@softwaremind.pl
tel./fax: +48-12 6145170
http://www.softwaremind.pl
 

Re: Getting directory in which app is deployed

Posted by Mike Sabroff <mi...@cygnusb2b.com>.
have your external process use a script that points to the webdirectory 
or if you use servlets, set an init param in the web.xml or in 
server.xml set an environment variable:
<!-- Test entry for demonstration purposes -->
    <Environment name="simpleValue" type="java.lang.Integer" value="30"/>
or set a session variable in a jsp

Wojciech Ciesielski wrote:
>
> Hi there,
>
> I have one problem... We have to execute external Java process from 
> JAR archive included in our web application directory. The problem is, 
> that all system dependant functions are relative to tomcat home 
> directory. And - when our application is deployed outside tomcat 
> directory via server.xml context definition - we cannot find a way to 
> get path to our web directory...
>
> I am not sure if I am expressing myself clear, so example...
>
> I have web app with structure:
>
> someDir/web:
>   WEB-INF
>   META-INF
>   dirWithArchive
>     externalProgram.jar
>   ...
>
> which is deployed OUTSIDE tomcat. I need to execute such code:
>
> Process = new ProcessBuilder("java -jar 
> some/path/to/someDir/web/dirWithArchive/externalProgram.jar".split("\\s+").start();
>
> from within struts action or struts plugin. HOW can I find a path 
> without specifying it manualy (it's problematic because of different 
> environments we deploy our application to).
>
> TIA
>
> Wojciech Ciesielski
> Software Mind | Where Quality Meets the Future
>
> mailto:woci@softwaremind.pl
> tel./fax: +48-12 6145170
> http://www.softwaremind.pl
>

-- 
Mike Sabroff
Web Services
Developer
mike.sabroff@cygnusb2b.com
920-568-8379


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Getting directory in which app is deployed

Posted by David Smith <dn...@cornell.edu>.
If your webapp is deployed as an exploded app (ie not a .war file), 
ServletContext#getRealPath() should do the trick

--David

Wojciech Ciesielski wrote:
> Hi there,
>
> I have one problem... We have to execute external Java process from JAR archive included in our web application directory. The problem is, that all system dependant functions are relative to tomcat home directory. And - when our application is deployed outside tomcat directory via server.xml context definition - we cannot find a way to get path to our web directory...
>
> I am not sure if I am expressing myself clear, so example...
>
> I have web app with structure:
>
> someDir/web:
>   WEB-INF
>   META-INF
>   dirWithArchive
>     externalProgram.jar
>   ...
>
> which is deployed OUTSIDE tomcat. I need to execute such code:
>
> Process = new ProcessBuilder("java -jar some/path/to/someDir/web/dirWithArchive/externalProgram.jar".split("\\s+").start();
>
> from within struts action or struts plugin. HOW can I find a path without specifying it manualy (it's problematic because of different environments we deploy our application to).
>
> TIA
>
> Wojciech Ciesielski
> Software Mind | Where Quality Meets the Future 
>  
> mailto:woci@softwaremind.pl
> tel./fax: +48-12 6145170
> http://www.softwaremind.pl
>  
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org