You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Todd O'Bryan <to...@mac.com> on 2004/03/15 04:06:37 UTC

Slightly OT: loading resources in a Tapestry application

I have a package that has to read a few files before it can do any 
work. In a previous, non-Tapestry incarnation, I put these files in the 
top directory of my web context, which I just pointed Tomcat toward on 
my development machine.

With Tapestry, I'm warring everything up and installing it using the 
Tomcat manager.

Here's my problem: I've tried sticking the files everywhere, I've tried 
using every ClassLoader.getSystemResourceAsStream() permutation I could 
think of, and things just don't seem to be working. When I run JUnit 
tests, the files get loaded, but I copy them elsewhere and run them in 
Tomcat, and no dice.

Suppose one of my files were "xyz.pwi". Where would you put that in the 
file system, and how would you load it once the code is all copied into 
Tomcat?

TIA,
Todd


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


RE: Slightly OT: loading resources in a Tapestry application

Posted by Petter Måhlén <pe...@elevance.se>.
I subclassed BaseEngine and put the below stuff for a createGlobal() method.
The rest of my engine class is empty, so it's not a big deal. WebApplication
is my own class, of course.

  protected Object createGlobal(RequestContext context) {

    WebApplication global = null;
    
    try {
      global = (WebApplication) super.createGlobal(context);
    }
    catch (ClassCastException e) {
      throw new ElevanceError("Unable to cast Global object into a
WebApplication instance", e);
    }

    String configFileName =
getPropertySource().getPropertyValue("se.elevance.timer.config-file");

    global.initialise(context.createSession().getServletContext(),
configFileName);

    return global;
  }

> -----Original Message-----
> From: Todd O'Bryan [mailto:toddobryan@mac.com] 
> Sent: den 15 mars 2004 11:27
> To: Tapestry users
> Subject: Re: Slightly OT: loading resources in a Tapestry application
> 
> 
> Is there an alternate way of doing this? I don't have my own Engine, 
> and I'd prefer not having to think about that if possible.
> 
> Alternatively, can I subclass the default Engine class and just put 
> this in createGlobal() or are there any gotchas that I also have to 
> take care of in createGlobal()?
> 
> Thanks,
> Todd
> 
> On Mar 15, 2004, at 4:27 AM, Petter Måhlén wrote:
> 
> > WEB-INF/classes should be included on your classpath. With 
> Tomcat, I 
> > am able
> > to read files from that location using 
> > ServletContext.getResourceAsStream().
> > I would think that using the ClassLoader is maybe a little 
> less sure to
> > work. To get the ServletContext, I do a
> > RequestContext.createSession().getServletContext() in my engine's
> > createGlobal() method.
> >
> > / Petter
> >
> >> -----Original Message-----
> >> From: Todd O'Bryan [mailto:toddobryan@mac.com]
> >> Sent: den 15 mars 2004 04:07
> >> To: Tapestry users
> >> Subject: Slightly OT: loading resources in a Tapestry application
> >>
> >>
> >> I have a package that has to read a few files before it can do any
> >> work. In a previous, non-Tapestry incarnation, I put these
> >> files in the
> >> top directory of my web context, which I just pointed Tomcat
> >> toward on
> >> my development machine.
> >>
> >> With Tapestry, I'm warring everything up and installing it 
> using the
> >> Tomcat manager.
> >>
> >> Here's my problem: I've tried sticking the files everywhere,
> >> I've tried
> >> using every ClassLoader.getSystemResourceAsStream()
> >> permutation I could
> >> think of, and things just don't seem to be working. When I 
> run JUnit
> >> tests, the files get loaded, but I copy them elsewhere and
> >> run them in
> >> Tomcat, and no dice.
> >>
> >> Suppose one of my files were "xyz.pwi". Where would you put
> >> that in the
> >> file system, and how would you load it once the code is all
> >> copied into
> >> Tomcat?
> >>
> >> TIA,
> >> Todd
> >>
> >>
> >> 
> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: 
> tapestry-user-unsubscribe@jakarta.apache.org
> >> For additional commands, e-mail: 
> tapestry-user-help@jakarta.apache.org
> >>
> >
> >
> > 
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: 
> tapestry-user-help@jakarta.apache.org
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Slightly OT: loading resources in a Tapestry application

Posted by Todd O'Bryan <to...@mac.com>.
Is there an alternate way of doing this? I don't have my own Engine, 
and I'd prefer not having to think about that if possible.

Alternatively, can I subclass the default Engine class and just put 
this in createGlobal() or are there any gotchas that I also have to 
take care of in createGlobal()?

Thanks,
Todd

On Mar 15, 2004, at 4:27 AM, Petter Måhlén wrote:

> WEB-INF/classes should be included on your classpath. With Tomcat, I 
> am able
> to read files from that location using 
> ServletContext.getResourceAsStream().
> I would think that using the ClassLoader is maybe a little less sure to
> work. To get the ServletContext, I do a
> RequestContext.createSession().getServletContext() in my engine's
> createGlobal() method.
>
> / Petter
>
>> -----Original Message-----
>> From: Todd O'Bryan [mailto:toddobryan@mac.com]
>> Sent: den 15 mars 2004 04:07
>> To: Tapestry users
>> Subject: Slightly OT: loading resources in a Tapestry application
>>
>>
>> I have a package that has to read a few files before it can do any
>> work. In a previous, non-Tapestry incarnation, I put these
>> files in the
>> top directory of my web context, which I just pointed Tomcat
>> toward on
>> my development machine.
>>
>> With Tapestry, I'm warring everything up and installing it using the
>> Tomcat manager.
>>
>> Here's my problem: I've tried sticking the files everywhere,
>> I've tried
>> using every ClassLoader.getSystemResourceAsStream()
>> permutation I could
>> think of, and things just don't seem to be working. When I run JUnit
>> tests, the files get loaded, but I copy them elsewhere and
>> run them in
>> Tomcat, and no dice.
>>
>> Suppose one of my files were "xyz.pwi". Where would you put
>> that in the
>> file system, and how would you load it once the code is all
>> copied into
>> Tomcat?
>>
>> TIA,
>> Todd
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


RE: Slightly OT: loading resources in a Tapestry application

Posted by Petter Måhlén <pe...@elevance.se>.
WEB-INF/classes should be included on your classpath. With Tomcat, I am able
to read files from that location using ServletContext.getResourceAsStream().
I would think that using the ClassLoader is maybe a little less sure to
work. To get the ServletContext, I do a
RequestContext.createSession().getServletContext() in my engine's
createGlobal() method.

/ Petter

> -----Original Message-----
> From: Todd O'Bryan [mailto:toddobryan@mac.com] 
> Sent: den 15 mars 2004 04:07
> To: Tapestry users
> Subject: Slightly OT: loading resources in a Tapestry application
> 
> 
> I have a package that has to read a few files before it can do any 
> work. In a previous, non-Tapestry incarnation, I put these 
> files in the 
> top directory of my web context, which I just pointed Tomcat 
> toward on 
> my development machine.
> 
> With Tapestry, I'm warring everything up and installing it using the 
> Tomcat manager.
> 
> Here's my problem: I've tried sticking the files everywhere, 
> I've tried 
> using every ClassLoader.getSystemResourceAsStream() 
> permutation I could 
> think of, and things just don't seem to be working. When I run JUnit 
> tests, the files get loaded, but I copy them elsewhere and 
> run them in 
> Tomcat, and no dice.
> 
> Suppose one of my files were "xyz.pwi". Where would you put 
> that in the 
> file system, and how would you load it once the code is all 
> copied into 
> Tomcat?
> 
> TIA,
> Todd
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org