You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Haller, Joe" <Jo...@purchasepro.com> on 2001/10/03 20:49:29 UTC

Finding Resources w/ Tomcat 4.0

I have a class that loads initialization properties
from a .properties text file in the same directory as the class.

The class resides in
/TOMCAT_HOME/webapps/myapp/WEB-INF/classes/com/company/app/PropertiesClass.c
lass
Properties reside in
/TOMCAT_HOME/webapps/myapp/WEB-INF/classes/com/company/app/PropertiesFile.pr
operties

I have a static initializer in PropertiesClass that builds the properties as
follows:

      ...
      ClassLoader loader = ClassLoader.getSystemClassLoader();
      URL url =
loader.getResource("com/company/app/PropertiesFile.properties");
      File file = new File(url.getFile());
      FileInputStream in = new FileInputStream(file);
      Properties props = new Properties();
      props.load(in);
      ...

Loading the properties in stand-alone through a test main method executes
correctly:

i.e.

/TOMCAT_HOME/webapps/myapp/WEB-INF/classes> java
com.company.app.PropertiesClass

However, when I use this class in Tomcat 4.0 the static initializer cannot
find
the file.  The class is being loaded but the .getResource() method in line 2
above
is not working correctly.  

Any ideas here?

Many thanks.
J. Haller

tomcat ajp13 errors(henri where are you?)

Posted by Marcel Stoer <ma...@bluewin.ch>.
Hi all

I've set up Tomcat 4.0 with IIS 5.0 and both servers run perfectly as
individuals (examples work). And now... integrating

Henri Gomez offers files (http://jakarta.apache.org/~hgomez/ajp13-tc4.0/)
and instructions for ajp13 and Tomcat 4.0. So, I followed his instructions
and afterwards the tc3.3 - iis howto
(http://jakarta.apache.org/tomcat/tomcat-3.3-doc/tomcat-iis-howto.html) .
HOWEVER, I must have made a minor but crucial mistake during the setup. All
checks (in howto) seem to be fine.

iis log:
19:12:24 127.0.0.1 GET /jakarta/isapi_redirect.dll 500

isapi log:
[jk_connect.c (143)]: jk_open_socket, connect() failed errno = 61
[jk_ajp13_worker.c (174)]: In jk_endpoint_t::connect_to_tomcat, failed errno
= 61
[jk_ajp13_worker.c (587)]: Error connecting to the Tomcat process.
[jk_isapi_plugin.c (554)]: HttpExtensionProc error, service() failed

in workers.properties:
worker.ajp13.port=8009
worker.ajp13.host=localhost
worker.ajp13.type=ajp13

in uriworkermap.properties:
/servlet/*=ajp13
/examples/*=ajp13

in server.xml:
<Connector className="org.apache.ajp.tomcat4.Ajp13Connector" port="8009"
minProcessors="5" maxProcessors="75" acceptCount="10" debug="0" />


Any hints greatly appreciated!!
Cheers, Marcel



Re: Finding Resources w/ Tomcat 4.0

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Wed, 3 Oct 2001, Will Stranathan wrote:

> Date: Wed, 03 Oct 2001 13:58:41 -0500
> From: Will Stranathan <wi...@thestranathans.com>
> Reply-To: tomcat-user@jakarta.apache.org
> To: tomcat-user@jakarta.apache.org
> Subject: Re: Finding Resources w/ Tomcat 4.0
>
> Your webapp is in a different classloader.  Webapps each get
> their own new classloader.
>
> Use something like this:
>
> ClassLoader loader = getClass().getClassLoader();
>

In addition to this, you should be aware that your proposed code will fail
if your webapp is being run directly from a WAR file rather than from an
unpacked directory.  A portable way to do this sort of thing would be:

  URL url = getClassLoader().getClass().getResource
    ("/com/company/app/PropertiesFile.properties");
  InputStream in = url.openStream();
  Properties props = new Properties();
  props.load(in);
  in.close();

> Will Stranathan
>

Craig McClanahan


> On Wed, 3 Oct 2001 11:49:29 -0700
>  "Haller, Joe" <Jo...@purchasepro.com> wrote:
> > I have a class that loads initialization properties
> > from a .properties text file in the same directory as the
> > class.
> >
> > The class resides in
> > /TOMCAT_HOME/webapps/myapp/WEB-INF/classes/com/company/app/PropertiesClass.c
> > lass
> > Properties reside in
> > /TOMCAT_HOME/webapps/myapp/WEB-INF/classes/com/company/app/PropertiesFile.pr
> > operties
> >
> > I have a static initializer in PropertiesClass that
> > builds the properties as
> > follows:
> >
> >       ...
> >       ClassLoader loader = ClassLoader.getSystemClassLoader();
> >       URL url =
> > loader.getResource("com/company/app/PropertiesFile.properties");
> >       File file = new File(url.getFile());
> >       FileInputStream in = new FileInputStream(file);
> >       Properties props = new Properties();
> >       props.load(in);
> >       ...
> >
> > Loading the properties in stand-alone through a test main
> > method executes
> > correctly:
> >
> > i.e.
> >
> > /TOMCAT_HOME/webapps/myapp/WEB-INF/classes> java
> > com.company.app.PropertiesClass
> >
> > However, when I use this class in Tomcat 4.0 the static
> > initializer cannot
> > find
> > the file.  The class is being loaded but the
> > .getResource() method in line 2
> > above
> > is not working correctly.
> >
> > Any ideas here?
> >
> > Many thanks.
> > J. Haller
>
>


Re: Finding Resources w/ Tomcat 4.0

Posted by Will Stranathan <wi...@thestranathans.com>.
Your webapp is in a different classloader.  Webapps each get
their own new classloader.

Use something like this:

ClassLoader loader = getClass().getClassLoader();

Will Stranathan

On Wed, 3 Oct 2001 11:49:29 -0700 
 "Haller, Joe" <Jo...@purchasepro.com> wrote:
> I have a class that loads initialization properties
> from a .properties text file in the same directory as the
> class.
> 
> The class resides in
> /TOMCAT_HOME/webapps/myapp/WEB-INF/classes/com/company/app/PropertiesClass.c
> lass
> Properties reside in
> /TOMCAT_HOME/webapps/myapp/WEB-INF/classes/com/company/app/PropertiesFile.pr
> operties
> 
> I have a static initializer in PropertiesClass that
> builds the properties as
> follows:
> 
>       ...
>       ClassLoader loader = ClassLoader.getSystemClassLoader();
>       URL url =
> loader.getResource("com/company/app/PropertiesFile.properties");
>       File file = new File(url.getFile());
>       FileInputStream in = new FileInputStream(file);
>       Properties props = new Properties();
>       props.load(in);
>       ...
> 
> Loading the properties in stand-alone through a test main
> method executes
> correctly:
> 
> i.e.
> 
> /TOMCAT_HOME/webapps/myapp/WEB-INF/classes> java
> com.company.app.PropertiesClass
> 
> However, when I use this class in Tomcat 4.0 the static
> initializer cannot
> find
> the file.  The class is being loaded but the
> .getResource() method in line 2
> above
> is not working correctly.  
> 
> Any ideas here?
> 
> Many thanks.
> J. Haller