Loading classes outside WEB-INF in Apache Tomcat

P

pradeep gummi

Hi all,
I have a web application that is working on Apache Web server
interacting with JServ. Now, I am trying to migrate from JServ to
Apache Tomcat 4.0 without disturbing the directory structure of the
the existing web application. I created a web app in tomcat which in
turn is trying to access these classes but only by creating jars or
moving these classes.
The different trials that I made are trying to place the jar files in
WEB-INF/lib directory, placing the classes in common/classes and in
server/classes. I am not able to figure out how to get it working with
out moving the classes.
I have realised that the options that I have are writing my own
classloader so as to load these classes in to the Tomcat. But I have
not figured out how to write these class loaders.
I checked in jakarta.apache.org regarding class loaders but wasnt
successful in gathering much info.
Please make suggestions if there are any other ways of doing this.
thanks
pradeep
 
D

dhek bhun kho

Hello Pradeep,

Pradeep said:
I am trying to explore other options without writing class loader since
the project requirement says that I should not write any JSPs for it. I

Have you read the example? It was only meant to show you how you can
access a new classloader from within your own code. You can also
instantiate a a classloader from within a servlet (or any other java
code) if the security policy permits it.

I almost forgot about this one, it's by far the easiest, but requires
that you have some kind of access to the system itself.

*nix: make a softlink (ln -s)

winNT/2k/XP: create a new partition and remount it as a directory
(seems you are working on this kind of system

I haven't ever worked on a real unix system, but I saw an option in the
GNU's 'mount' utility to rebind a directory at a different mountpoint:

mount --bind (take a look at the man pages)

If you're working on a Mac, I know no option to solve this.
would like to know if I can add any classloaders apart from common or
catalina and System class loaders.
I was also looking in to the catalina.policy file which mentions about
the class by adding the following code:
I have my JServ classes placed in the
C:/abc/mindbridge/Intrasmart/saclasses directory. And I have tomcat
installed in C:/Tomcat directory.
I would like to have some class loader which loads these saclasses in
to the Tomcat Directory by adding the following lines of code in the
catalina.policy file.

grant codeBase "file:C:/abc/mindbridge/Intrasmart/saclasses/-" {
permission java.security.AllPermission;
};

Somehow I never liked the idea of having AllPermission for anything
connected to the outside world, call me paranoid if you will. If it's
possible to solve it by manipulating the way the filesystem is ordered,
I'd rather go with that, as the whole problem is kind of implementation
specific, and you don't want it to end up in your code. If possible, do
try to avoid having to create a new classloader yourself unless it is
absolutely necessary.

The problem has been all the class loaders are relative to the
CATALINA_HOME.

By far the 'solution' to bind a partition to a NTFS folder is the
easiest. If you really do want to write a custom a classloader you ought
to have a look at the org.apache.catalina.loader.* sources for the class
loader implementations used by tomcat (4 and later); or hack the classes
in org.apache.catalina.startup like Bootstrap and ClassLoaderFactory, I
saw some hardcoded paths there.

Greets
Bhun.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top