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

F

funnysun

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
 
M

Mark Space

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?

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.
 
J

Juha Laiho

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)
 
S

Simon Brooke

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
 
S

Simon Brooke

Juha Laiho said:
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.
 

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,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top