How to configure context.xml aliases for Tomcat 7?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How to configure context.xml aliases for Tomcat 7?

cdavis226
I wanted to use Tomcat 7 context.xml aliases for static files in my grails application as referenced in point 4 of this page:
http://www.developer.com/java/web/article.php/3904871/Top-7-Features-in-Tomcat-7-The-New-and-the-Improved.htm

But I am completely lost as to how to go about creating the alias in development (using the embedded tomcat) and production (where I deploy the war file).

I have googled and seen references to modifying the Events.groovy file, and I've seen references to creating a context.xml file the META-INF folder. But I can't seem to find any complete examples, and the whole context.xml file thing really confuses me because it doesn't seem to exist when working with grails.

Can someone shed some light for me?
Reply | Threaded
Open this post in threaded view
|

Re: How to configure context.xml aliases for Tomcat 7?

cdavis226
This post was updated on .
As with many things in Grails, this appears to be simpler that I expected. The following example would be for a Windows machine.

In development using the embedded Tomcat with run-app, put an event closure in Events.groovy (inside the scripts folder). Aside - I see many references to _Events.groovy and some to Events.groovy. Does it matter? I used Events (without the underscore) and it seems to work fine.

Events.groovy:
eventConfigureTomcat = {tomcat ->
    def ctx=tomcat.host.findChild(serverContextPath)
    if ( ctx.aliases ) {
        ctx.aliases += ',/photos=c:\\temp\\photos'
    } else {
        ctx.aliases = '/photos=c:\\temp\\photos'
    }
}
For the standalone context, create a Context.xml file and put into your META-INF folder.
The contents of the file can be as simple as:
<context aliases="/photos=c:\\temp\\photos"></context>
Now I can reference photos in my application using
 <img src="/photos/test.jpg"/> 
 or something similar.
Reply | Threaded
Open this post in threaded view
|

Re: How to configure context.xml aliases for Tomcat 7?

Ian Roberts
On 26/07/2012 15:44, cdavis226 wrote:
> As with many things in Grails, this appears to be simpler that I expected.
> The following example would be for a Windows machine.
>
> In development using the embedded Tomcat with run-app, put an event closure
> in Events.groovy (inside the scripts folder). Aside - I see many references
> to _Events.groovy and some to Events.groovy. Does it matter? I used Events
> (without the underscore) and it seems to work fine.

Events.groovy (without the underscore) was the original name for this
file but the recommended name changed to _Events.groovy somewhere in
Grails 1.0.x/1.1.x (I don't remember what version exactly).  The
non-underscore name has been deprecated ever since.

Ian

--
Ian Roberts               | Department of Computer Science
[hidden email]  | University of Sheffield, UK

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: How to configure context.xml aliases for Tomcat 7?

senthilnathan
I am using default glassfish server. I followed the steps mentioned in the post by using Context.xml for alias name. But i am getting error message as "Not allowed to load local resource" in the browser console. Can you help me with this issue.