Tomcat symbolic links and running servlets

J

Jim

Hi,

This is my first post, so I hope this belongs to this group. If not
please point me in the right direction.

I'm trying to get Tomcat to execute a servlet outside the
tomcat/webapps/any_name_here/WEB-INF directory. I made a copy of the
examples dir under tomcat/webapps and renamed the folder jim under
C:\
I got the servlets to execute. But if I try to run a servlet outside
the WEB-INF dir I get errors.

Can I get a servlet to run when not under the WEB-INF directory?


Thanks in advance,

Jim
 
W

Wendy S

Jim said:
This is my first post, so I hope this belongs to this group. If not
please point me in the right direction.
I'm trying to get Tomcat to execute a servlet outside the
tomcat/webapps/any_name_here/WEB-INF directory. I made a copy of the
examples dir under tomcat/webapps and renamed the folder jim under
C:\
I got the servlets to execute. But if I try to run a servlet outside
the WEB-INF dir I get errors.
Can I get a servlet to run when not under the WEB-INF directory?

The best reference on questions like this is the Servlet Specification,
(Either 2.3 or 2.2 depending on what version of Tomcat you're using,) which
you can download from Sun.

I scanned through the Servlet 2.3 spec and don't see anything that requires
Tomcat to do what you're asking. So I suspect that if you really want this
behavior you'll have to write your own class loader or modify the Tomcat
source.

A webapp is nothing but a bunch of files arranged in a special way. One
reason the .class files go in WEB-INF is because the Servlet container is
specifically prohibited from directly serving things in it. So a client
browser can't get to your .properties files, Java .class files, etc.

Can you explain more about why you need this behavior? Maybe there's an
easier and better solution to your problem. And what do symbolic links (in
your subject) have to do with it?
 
J

Jim

Wendy S said:
The best reference on questions like this is the Servlet Specification,
(Either 2.3 or 2.2 depending on what version of Tomcat you're using,) which
you can download from Sun.

I scanned through the Servlet 2.3 spec and don't see anything that requires
Tomcat to do what you're asking. So I suspect that if you really want this
behavior you'll have to write your own class loader or modify the Tomcat
source.

A webapp is nothing but a bunch of files arranged in a special way. One
reason the .class files go in WEB-INF is because the Servlet container is
specifically prohibited from directly serving things in it. So a client
browser can't get to your .properties files, Java .class files, etc.

Can you explain more about why you need this behavior? Maybe there's an
easier and better solution to your problem. And what do symbolic links (in
your subject) have to do with it?

Hi Wendy,

I am working on a project where I'm not allowed to mess with the
directory structure that already exists. The project had been served
by jserv but I'm supposed to transfer it to Tomcat. I'm not sure how
jserv works, but it ran the servlets in their various directories.

The symbolic links are the only way I found to get Tomcat to "see"
outside its directory. Someone suggested symbolic links and when I
did a search I found this:

<Context path="/myApp" docBase="myApp" debug="0">
<Resources className="org.apache.naming.resources.FileDirContext"
allowLinking="true" />
</Context>

And it works to a point.
If I give docBase="C:\servlets" it gives me a gopher listing of the
directory.
 
W

Wendy S

Jim said:
I am working on a project where I'm not allowed to mess with the
directory structure that already exists. The project had been served
by jserv but I'm supposed to transfer it to Tomcat. I'm not sure how
jserv works, but it ran the servlets in their various directories.

The symbolic links are the only way I found to get Tomcat to "see"
outside its directory. Someone suggested symbolic links and when I
did a search I found this:

<Context path="/myApp" docBase="myApp" debug="0">
<Resources className="org.apache.naming.resources.FileDirContext"
allowLinking="true" />
</Context>

And it works to a point.
If I give docBase="C:\servlets" it gives me a gopher listing of the
directory.

Assuming c:\servlets contains .class files, it would not be the docbase, it
would be the WEB-INF\classes directory. What if you create a separate
mycontext directory, use *that* as the docbase, then create a WEB-INF
directory containing a soft link to c:\servlets?

I don't see exactly what the problem is. What do your <servlet> and
<servlet-mapping> tags look like? What errors are you getting?

But I don't understand this edict that you can't change the directory
structure. I don't see why you would *need* to-- surely JServ is compliant
with the Servlet spec (it's an Apache project, right?) So what is so
different about the project in JServ that makes it not work in Tomcat?

Do you have one c:\servlets\my\package\MyServlet.class that you are trying
to use in *both* Tomcat and JServ at the same time?

This might help: http://www.linuxroot.org/apachecon/T06.pdf
(Craig McClanahan on converting JServ webapps to Tomcat)
 
J

Jim

Wendy S said:
Assuming c:\servlets contains .class files, it would not be the docbase, it
would be the WEB-INF\classes directory. What if you create a separate
mycontext directory, use *that* as the docbase, then create a WEB-INF
directory containing a soft link to c:\servlets?

I don't see exactly what the problem is. What do your <servlet> and
<servlet-mapping> tags look like? What errors are you getting?

But I don't understand this edict that you can't change the directory
structure. I don't see why you would *need* to-- surely JServ is compliant
with the Servlet spec (it's an Apache project, right?) So what is so
different about the project in JServ that makes it not work in Tomcat?

Do you have one c:\servlets\my\package\MyServlet.class that you are trying
to use in *both* Tomcat and JServ at the same time?

This might help: http://www.linuxroot.org/apachecon/T06.pdf
(Craig McClanahan on converting JServ webapps to Tomcat)

The project I'm interning on has been around for several years.
Changing the directory structure would cost countless man hours and
introduce new bugs to the system. I'm don't have enough info to tell
you why the project is moving to Tomcat. I heard it may have
something with moving away from using Sapphire with JServ. And Tomcat
can help with that. Now I heard they got the project to work with
Tomcat before. But they forget how it worked after they broke it.

I got some of the required servlets to run using a WEB-INF folder.
But some of the other servlets call others in different directories.
And that those cause errors -> HTTP Status 500 and HTTP Status 503
when I hit reload.
Do you have one c:\servlets\my\package\MyServlet.class that you are trying
to use in *both* Tomcat and JServ at the same time?
Nope. JServ is turned off.

Here is my servlet tags :

<servlet>
<servlet-name>S1JIMServlet</servlet-name>
<servlet-class>JIMApi.S1JIMServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>S1JIMServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>

Now I may be splitting hairs, but the Servlet 2.3 spec says "MAY
place it under this directory" talking about(WEB-INF). Not "should"
and not "has to". Correct me if I'm wrong but, I think I should be
able to bend the rules in Servlet 2.3 spec.

I'm starting to think I should make a class Loader like you suggested.
But I can't find the source code for the Tomcat class loader, to base
mine on. Do you know of any good places to look?

Thanks,
Jim
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top