You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Jordan Michaels <jo...@viviotech.net> on 2008/09/10 01:47:41 UTC

relative paths in web.xml

I'm trying to set up a "init-param" in Tomcat's main web.xml file (the
one in $CATALINA_HOME/conf/web.xml) that looks similar to the following:

<servlet>
        <servlet-name>myServlet</servlet-name>
        <servlet-class>path.to.my.Servlet</servlet-class>
        <init-param>
            <param-name>SOME_XML_FILE</param-name>
            <param-value>./conf/myservlet/myxmlfile.xml</param-value>
        </init-param>
        <load-on-startup>0</load-on-startup>
</servlet>

and in my $CATALINA_HOME/conf/server.xml file, I have the following:

<Host name="mydomain.net" appBase="webapps"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false">
        <Context path="" docBase="/home/myuser/public_html/" />
</Host>

My XML file is in $CATALINA_HOME/conf/myservlet/myxmlfile.xml, but
whenever I load this up, Tomcat looks for the file under the
/home/myuser/public_html/ folder.

Is there a way that I can tell tomcat to look for a file that's relative
to the $CATALINA_HOME folder instead of my Context Docbase value? It
would be ideal if the Param-Value had no relation to the Context Docbase
value at all.

Is this even possible with Tomcat?

Thanks in advance for any help anyone can offer.

-- 
Warm regards,
Jordan Michaels
Vivio Technologies
http://www.viviotech.net/
Open BlueDragon Steering Committee
Adobe Solution Provider

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


Re: relative paths in web.xml [solved]

Posted by Jordan Michaels <jo...@viviotech.net>.
Just so folks are aware, this has been solved. Apparently is was the
servlet that was resolving the location of the XML file based off the
Context Docbase, and there was a trick to getting it to realize that the
file path you were passing to it was a full file path and not a relative
file path.

In this case, it was simply putting a $ at the beginning of the value
that did the trick. IE:

<param-value>$${catalina.home}/conf/myservlet/myxmlfile.xml</param-value>

Worked like a charm!

Just note that this fix was specific to the servlet that I was using,
and not all servlets work the same, so this fix may not work for you.

Thanks again to all that helped me with this issue. It was most appreciated!

Warm regards,
Jordan Michaels
Vivio Technologies
http://www.viviotech.net/
Open BlueDragon Steering Committee
Adobe Solution Provider


Jordan Michaels wrote:
> Hmm... I tried this, and it looks as though Tomcat still pre-pends the
> "/home/myuser/public_html/" to my XML file. My servlet throws the error:
> 
> java.io.FileNotFoundException:
> /home/myuser/public_html/path/to/tomcat/conf/myservlet/myxmlfile.xml
> 
> and my file is really located at:
> 
> /path/to/tomcat/conf/myservlet/myxmlfile.xml
> 
> I have multiple sites that need to have access to this same servlet with
> the same XML file passed to it, and it would be great if I didn't have
> to copy this file to each site for each HOST entry... IE:
> 
> <Host name="mydomain1.net" appBase="webapps">
>        <Context path="" docBase="/home/myuser1/public_html/" />
> </Host>
> 
> <Host name="mydomain2.net" appBase="webapps">
>        <Context path="" docBase="/home/myuser2/public_html/" />
> </Host>
> 
> <Host name="mydomain3.net" appBase="webapps">
>        <Context path="" docBase="/home/myuser3/public_html/" />
> </Host>
> 
> The way Tomcat is working now, I would have to copy that XML file that I
> need to pass to the servlet to each user's "public_html" directory in
> order for the servlet to use it (which would also make the file
> web-accessible - not at all what I want).
> 
> Is there a way to tell Tomcat to not use the docbase when passing this
> file to the servlet?
> 
> Thanks to all of you who responded both on-list and off. =) I really
> appreciate your help!
> 
> Warm regards,
> Jordan Michaels
> Vivio Technologies
> http://www.viviotech.net/
> Open BlueDragon Steering Committee
> Adobe Solution Provider
> 
> 
> Bill Barker wrote:
>> "Jordan Michaels" <jo...@viviotech.net> wrote in message 
>> news:48C70B1D.2020907@viviotech.net...
>>> I'm trying to set up a "init-param" in Tomcat's main web.xml file (the
>>> one in $CATALINA_HOME/conf/web.xml) that looks similar to the following:
>>>
>>> <servlet>
>>>        <servlet-name>myServlet</servlet-name>
>>>        <servlet-class>path.to.my.Servlet</servlet-class>
>>>        <init-param>
>>>            <param-name>SOME_XML_FILE</param-name>
>>>            <param-value>./conf/myservlet/myxmlfile.xml</param-value>
>>>        </init-param>
>>>        <load-on-startup>0</load-on-startup>
>>> </servlet>
>>>
>>> and in my $CATALINA_HOME/conf/server.xml file, I have the following:
>>>
>>> <Host name="mydomain.net" appBase="webapps"
>>>            unpackWARs="true" autoDeploy="true"
>>>            xmlValidation="false" xmlNamespaceAware="false">
>>>        <Context path="" docBase="/home/myuser/public_html/" />
>>> </Host>
>>>
>>> My XML file is in $CATALINA_HOME/conf/myservlet/myxmlfile.xml, but
>>> whenever I load this up, Tomcat looks for the file under the
>>> /home/myuser/public_html/ folder.
>>>
>>> Is there a way that I can tell tomcat to look for a file that's relative
>>> to the $CATALINA_HOME folder instead of my Context Docbase value? It
>>> would be ideal if the Param-Value had no relation to the Context Docbase
>>> value at all.
>>>
>>> Is this even possible with Tomcat?
>>>
>> This feature is specific to Tomcat, but yes you can do it.  You would use:
>>    <param-value>${catalina.home}/conf/myservlet/myxmlfile.xml</param-value>
>>
>> When Tomcat parses your web.xml file, it will substitute the value for the 
>> System property catalina.home.  Of course, this works for any System 
>> property.
>>
>>
>>> Thanks in advance for any help anyone can offer.
>>>
>>> -- 
>>> Warm regards,
>>> Jordan Michaels
>>> Vivio Technologies
>>> http://www.viviotech.net/
>>> Open BlueDragon Steering Committee
>>> Adobe Solution Provider
>>>
>>> ---------------------------------------------------------------------
>>> To start a new topic, e-mail: users@tomcat.apache.org
>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>
>>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 

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


Re: relative paths in web.xml

Posted by Jordan Michaels <jo...@viviotech.net>.
Hmm... I tried this, and it looks as though Tomcat still pre-pends the
"/home/myuser/public_html/" to my XML file. My servlet throws the error:

java.io.FileNotFoundException:
/home/myuser/public_html/path/to/tomcat/conf/myservlet/myxmlfile.xml

and my file is really located at:

/path/to/tomcat/conf/myservlet/myxmlfile.xml

I have multiple sites that need to have access to this same servlet with
the same XML file passed to it, and it would be great if I didn't have
to copy this file to each site for each HOST entry... IE:

<Host name="mydomain1.net" appBase="webapps">
       <Context path="" docBase="/home/myuser1/public_html/" />
</Host>

<Host name="mydomain2.net" appBase="webapps">
       <Context path="" docBase="/home/myuser2/public_html/" />
</Host>

<Host name="mydomain3.net" appBase="webapps">
       <Context path="" docBase="/home/myuser3/public_html/" />
</Host>

The way Tomcat is working now, I would have to copy that XML file that I
need to pass to the servlet to each user's "public_html" directory in
order for the servlet to use it (which would also make the file
web-accessible - not at all what I want).

Is there a way to tell Tomcat to not use the docbase when passing this
file to the servlet?

Thanks to all of you who responded both on-list and off. =) I really
appreciate your help!

Warm regards,
Jordan Michaels
Vivio Technologies
http://www.viviotech.net/
Open BlueDragon Steering Committee
Adobe Solution Provider


Bill Barker wrote:
> "Jordan Michaels" <jo...@viviotech.net> wrote in message 
> news:48C70B1D.2020907@viviotech.net...
>> I'm trying to set up a "init-param" in Tomcat's main web.xml file (the
>> one in $CATALINA_HOME/conf/web.xml) that looks similar to the following:
>>
>> <servlet>
>>        <servlet-name>myServlet</servlet-name>
>>        <servlet-class>path.to.my.Servlet</servlet-class>
>>        <init-param>
>>            <param-name>SOME_XML_FILE</param-name>
>>            <param-value>./conf/myservlet/myxmlfile.xml</param-value>
>>        </init-param>
>>        <load-on-startup>0</load-on-startup>
>> </servlet>
>>
>> and in my $CATALINA_HOME/conf/server.xml file, I have the following:
>>
>> <Host name="mydomain.net" appBase="webapps"
>>            unpackWARs="true" autoDeploy="true"
>>            xmlValidation="false" xmlNamespaceAware="false">
>>        <Context path="" docBase="/home/myuser/public_html/" />
>> </Host>
>>
>> My XML file is in $CATALINA_HOME/conf/myservlet/myxmlfile.xml, but
>> whenever I load this up, Tomcat looks for the file under the
>> /home/myuser/public_html/ folder.
>>
>> Is there a way that I can tell tomcat to look for a file that's relative
>> to the $CATALINA_HOME folder instead of my Context Docbase value? It
>> would be ideal if the Param-Value had no relation to the Context Docbase
>> value at all.
>>
>> Is this even possible with Tomcat?
>>
> 
> This feature is specific to Tomcat, but yes you can do it.  You would use:
>    <param-value>${catalina.home}/conf/myservlet/myxmlfile.xml</param-value>
> 
> When Tomcat parses your web.xml file, it will substitute the value for the 
> System property catalina.home.  Of course, this works for any System 
> property.
> 
> 
>> Thanks in advance for any help anyone can offer.
>>
>> -- 
>> Warm regards,
>> Jordan Michaels
>> Vivio Technologies
>> http://www.viviotech.net/
>> Open BlueDragon Steering Committee
>> Adobe Solution Provider
>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 

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


Re: relative paths in web.xml

Posted by Bill Barker <wb...@wilshire.com>.
"Jordan Michaels" <jo...@viviotech.net> wrote in message 
news:48C70B1D.2020907@viviotech.net...
> I'm trying to set up a "init-param" in Tomcat's main web.xml file (the
> one in $CATALINA_HOME/conf/web.xml) that looks similar to the following:
>
> <servlet>
>        <servlet-name>myServlet</servlet-name>
>        <servlet-class>path.to.my.Servlet</servlet-class>
>        <init-param>
>            <param-name>SOME_XML_FILE</param-name>
>            <param-value>./conf/myservlet/myxmlfile.xml</param-value>
>        </init-param>
>        <load-on-startup>0</load-on-startup>
> </servlet>
>
> and in my $CATALINA_HOME/conf/server.xml file, I have the following:
>
> <Host name="mydomain.net" appBase="webapps"
>            unpackWARs="true" autoDeploy="true"
>            xmlValidation="false" xmlNamespaceAware="false">
>        <Context path="" docBase="/home/myuser/public_html/" />
> </Host>
>
> My XML file is in $CATALINA_HOME/conf/myservlet/myxmlfile.xml, but
> whenever I load this up, Tomcat looks for the file under the
> /home/myuser/public_html/ folder.
>
> Is there a way that I can tell tomcat to look for a file that's relative
> to the $CATALINA_HOME folder instead of my Context Docbase value? It
> would be ideal if the Param-Value had no relation to the Context Docbase
> value at all.
>
> Is this even possible with Tomcat?
>

This feature is specific to Tomcat, but yes you can do it.  You would use:
   <param-value>${catalina.home}/conf/myservlet/myxmlfile.xml</param-value>

When Tomcat parses your web.xml file, it will substitute the value for the 
System property catalina.home.  Of course, this works for any System 
property.


> Thanks in advance for any help anyone can offer.
>
> -- 
> Warm regards,
> Jordan Michaels
> Vivio Technologies
> http://www.viviotech.net/
> Open BlueDragon Steering Committee
> Adobe Solution Provider
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
> 




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