Newbie question-- where to put java class file in Tomcat server

Discussion in 'Java' started by funnysun, Dec 5, 2006.

  1. funnysun

    funnysun Guest

    I have installed Tomcat and created a little java class for jsp page.
    however, it does not work and I looked up all referrences, but found
    the location of .class file varies. Could someone please let me know
    where should I put .class file?

    Thanks
     
    funnysun, Dec 5, 2006
    #1
    1. Advertising

  2. funnysun

    Mark Space Guest

    funnysun wrote:
    > I have installed Tomcat and created a little java class for jsp page.
    > however, it does not work and I looked up all referrences, but found
    > the location of .class file varies. Could someone please let me know
    > where should I put .class file?
    >
    > Thanks
    >


    A short answer is that they need to go in:

    "tomcat home"/tomcat/webapps/"your web app"/WEB-INF/classes/

    Don't forget to add directories for the full class name. If you class
    is com.example.myClass, then com/example/myClass.class is what goes
    under /classes/.

    A better answer is that you should wrap you full app in a war file. War
    files are the same as jar files, they just have a few extra required
    files, like the addition of the WEB-INF directory mentioned above.

    Do a wep search on "JSP deployment," that might help. There's several
    ways to deploy a JSP web app. I can also recomend Head First Servlets &
    JSP by O'Reilly. It goes into all the hairy details.
     
    Mark Space, Dec 5, 2006
    #2
    1. Advertising

  3. funnysun

    Juha Laiho Guest

    "funnysun" <> said:
    >I have installed Tomcat and created a little java class for jsp page.
    >however, it does not work and I looked up all referrences, but found
    >the location of .class file varies. Could someone please let me know
    >where should I put .class file?


    First thing is that the class should belong to a package.

    After that, the class should either
    - be packaged into a JAR file (with pakcage structure intact in the JAR)
    - or be placed within WEB-INF/classes, maintaining the package structure
    (so, f.ex. if the class MyClass belongs to package myPack, the class
    file should be named WEB-INF/classes/myPack/MyClass.class)
    --
    Wolf a.k.a. Juha Laiho Espoo, Finland
    (GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
    PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
    "...cancel my subscription to the resurrection!" (Jim Morrison)
     
    Juha Laiho, Dec 5, 2006
    #3
  4. funnysun

    Simon Brooke Guest

    in message <>,
    funnysun ('') wrote:

    > I have installed Tomcat and created a little java class for jsp page.
    > however, it does not work and I looked up all referrences, but found
    > the location of .class file varies. Could someone please let me know
    > where should I put .class file?


    webapps/yourwebapp/WEB-INF/classes

    or if you pack several class files up into a jar file

    webapps/yourwebapp/WEB-INF/lib

    --
    (Simon Brooke) http://www.jasmine.org.uk/~simon/
    ;; If God does not write LISP, God writes some code so similar to
    ;; LISP as to make no difference.
     
    Simon Brooke, Dec 6, 2006
    #4
  5. funnysun

    Simon Brooke Guest

    in message <el4aet$ic4$-int>, Juha Laiho
    ('') wrote:

    > "funnysun" <> said:
    >>I have installed Tomcat and created a little java class for jsp page.
    >>however, it does not work and I looked up all referrences, but found
    >>the location of .class file varies. Could someone please let me know
    >>where should I put .class file?

    >
    > First thing is that the class should belong to a package.
    >
    > After that, the class should either
    > - be packaged into a JAR file (with pakcage structure intact in the JAR)
    > - or be placed within WEB-INF/classes, maintaining the package structure
    > (so, f.ex. if the class MyClass belongs to package myPack, the class
    > file should be named WEB-INF/classes/myPack/MyClass.class)


    .... but package names should be prefixed with your domain name in JANET
    syntax, and should be in lower case.

    So, supposing your domain is yourdomain.org, actually

    /webapps/yourwebapp/WEB-INF/classes/org/yourdomain/mypack/MyClass

    Having said that I wouldn't do that. I'd only use the WEB-INF/classes
    subdirectory for properties files. Classes belong in packages and packages
    belong in jars and jars belong in WEB-INF/lib.

    --
    (Simon Brooke) http://www.jasmine.org.uk/~simon/


    ... a mild, inoffensive sadist...
     
    Simon Brooke, Dec 6, 2006
    #5
  6. funnysun

    funnysun Guest

    Thanks to everyone, I will try later on and post result here.=)
    Simon Brooke wrote:
    > in message <el4aet$ic4$-int>, Juha Laiho
    > ('') wrote:
    >
    > > "funnysun" <> said:
    > >>I have installed Tomcat and created a little java class for jsp page.
    > >>however, it does not work and I looked up all referrences, but found
    > >>the location of .class file varies. Could someone please let me know
    > >>where should I put .class file?

    > >
    > > First thing is that the class should belong to a package.
    > >
    > > After that, the class should either
    > > - be packaged into a JAR file (with pakcage structure intact in the JAR)
    > > - or be placed within WEB-INF/classes, maintaining the package structure
    > > (so, f.ex. if the class MyClass belongs to package myPack, the class
    > > file should be named WEB-INF/classes/myPack/MyClass.class)

    >
    > ... but package names should be prefixed with your domain name in JANET
    > syntax, and should be in lower case.
    >
    > So, supposing your domain is yourdomain.org, actually
    >
    > /webapps/yourwebapp/WEB-INF/classes/org/yourdomain/mypack/MyClass
    >
    > Having said that I wouldn't do that. I'd only use the WEB-INF/classes
    > subdirectory for properties files. Classes belong in packages and packages
    > belong in jars and jars belong in WEB-INF/lib.
    >
    > --
    > (Simon Brooke) http://www.jasmine.org.uk/~simon/
    >
    >
    > ... a mild, inoffensive sadist...
     
    funnysun, Dec 16, 2006
    #6
    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. sjoshi
    Replies:
    0
    Views:
    6,691
    sjoshi
    Sep 27, 2005
  2. E11
    Replies:
    1
    Views:
    4,948
    Thomas Weidenfeller
    Oct 12, 2005
  3. Sean Berry
    Replies:
    3
    Views:
    4,589
    Tim Terry
    Dec 19, 2005
  4. Angus
    Replies:
    1
    Views:
    300
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=
    Nov 26, 2006
  5. Gabriel Rossetti
    Replies:
    3
    Views:
    601
    Jerry Hill
    Apr 25, 2008
Loading...

Share This Page