Tomcat symbolic links and running servlets

Discussion in 'Java' started by Jim, Aug 7, 2003.

  1. Jim

    Jim Guest

    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
     
    Jim, Aug 7, 2003
    #1
    1. Advertising

  2. Jim

    Wendy S Guest

    Jim wrote:
    > 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?

    --
    Wendy in Chandler, AZ
     
    Wendy S, Aug 7, 2003
    #2
    1. Advertising

  3. Jim

    Jim Guest

    Wendy S <> wrote in message news:<BbhYa.1345$Qe.110@fed1read04>...
    > Jim wrote:
    > > 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?


    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.
     
    Jim, Aug 7, 2003
    #3
  4. Jim

    Wendy S Guest

    Jim wrote:
    > 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)

    --
    Wendy in Chandler, AZ
     
    Wendy S, Aug 8, 2003
    #4
  5. Jim

    Jim Guest

    Wendy S <> wrote in message news:<4KFYa.1552$Qe.731@fed1read04>...
    > Jim wrote:
    > > 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)


    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
     
    Jim, Aug 8, 2003
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Juha Laiho
    Replies:
    0
    Views:
    692
    Juha Laiho
    Jul 20, 2004
  2. Nick Howes
    Replies:
    6
    Views:
    581
    Toby A Inkster
    Nov 24, 2003
  3. pekka.niiranen
    Replies:
    0
    Views:
    277
    pekka.niiranen
    Feb 10, 2004
  4. Don McClean

    Rake::Filelist and symbolic links

    Don McClean, Jul 2, 2007, in forum: Ruby
    Replies:
    0
    Views:
    132
    Don McClean
    Jul 2, 2007
  5. Zouplaz

    Require and symbolic links

    Zouplaz, Nov 9, 2008, in forum: Ruby
    Replies:
    3
    Views:
    104
    Martin DeMello
    Nov 10, 2008
Loading...

Share This Page