classpath for web-application.

I am working on a web application with a bunch of jsp files using some

java classes. I am using tomcat 5.5. I have a special class file, say

a.class, sit in the web-inf/classes. This class import another two

jars, say b.jar and c.jar.The jsp file will import a and does not

use b and c.How should I organize them for a war file in server?

I actually write a.java with the jsp file in a web project in netbean

5.5. And the created war file put b.jar and c.jar in web-inf/lib. But

when I deploy the war file, I keep get the

"java.lang.NoClassDefFoundError: org/kowari/itql/ItqlInterpreterBean"

(this is a class in b.jar).I test compiling all the jsp in compile

and it works. I suppose you can specify these classpath related

information somewhere in web-application directory.How to put

everything? Thank you.

[887 byte] By [shmilylemon@yahoo.coma] at [2007-10-3 9:41:03]
# 1

I looked at it more carefully. Actually the a.class only use something from b.jar. While b.jar use c.jar indirectly. I tried to put a.class's content into the jsp code then I import packages from both b.jar and c.jar. I then told me the package in the c.jar does not existed, while both b.jar and c.jar in the final war file. It got to do with the the classpath setting of tomcat. I tried to add c.jar into the "classpath" variable. I am using java 1.5 in windows xp.It does not work.

shmilylemon@yahoo.coma at 2007-7-15 4:57:07 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

The .jar files should go into WEB-INF/lib.

Your .class files should be in package and should be placed in the WEB-INF/classes folder with the package structure intact. So if the package is 'test', the class file should be in WEB-INF/classes/test/a.class

Does that help?

ram.

Madathil_Prasada at 2007-7-15 4:57:07 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

> The .jar files should go into WEB-INF/lib.

> Your .class files should be in package and should be

> placed in the WEB-INF/classes folder with the package

> structure intact. So if the package is 'test', the

> class file should be in WEB-INF/classes/test/a.class

> Does that help?

>

> ram.

But that is what exactly what is in the war file. I still get "java.lang.NoClassDefFoundError: org/kowari/itql/ItqlInterpreterBean"

This error seems to do with the classpath setting.

shmilylemon@yahoo.coma at 2007-7-15 4:57:07 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Assuming that ItqlInterpreterBean is in the c.jar make sure that there are no instances of b.jar in the commons/lib or shared/lib directories.
tolmanka at 2007-7-15 4:57:07 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

ItqlInterpreterBean is in the c.jar.What do you mean no instances? I am quite a beginner and do not quite understand. Besides, b.jar and c.jar actually are from others, they are some database connection package. I have no access to their source.They do have javadoc and I can learn the interface information there, though.

Message was edited by:

shmilylemon@yahoo.com

shmilylemon@yahoo.coma at 2007-7-15 4:57:07 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
Post your web application folder structure here.
Madathil_Prasada at 2007-7-15 4:57:07 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

This is the result of "jar tf display.war".The one I am talking about is KowariStore.class. It use WEB-INF/lib/tupelo2.jar, which use WEB-INF/lib/kowari-1.2.0.jar.The problem is

java.lang.NoClassDefFoundError: org/kowari/itql/ItqlInterpreterBean, this is a package in "kowari-1.2.0.jar".

META-INF/

META-INF/MANIFEST.MF

WEB-INF/

WEB-INF/classes/

WEB-INF/classes/edu/

WEB-INF/classes/edu/uiuc/

WEB-INF/classes/edu/uiuc/lis/

WEB-INF/classes/edu/uiuc/lis/brain/

WEB-INF/lib/

images/

META-INF/context.xml

WEB-INF/bottom.jspf

WEB-INF/classes/edu/uiuc/lis/brain/BrainDB$Database.class

WEB-INF/classes/edu/uiuc/lis/brain/BrainDB.class

WEB-INF/classes/edu/uiuc/lis/brain/KowariStore.class

WEB-INF/classes/edu/uiuc/lis/brain/uiucdoc$Columns.class

WEB-INF/classes/edu/uiuc/lis/brain/uiucdoc$Database.class

WEB-INF/classes/edu/uiuc/lis/brain/uiucdoc.class

WEB-INF/lib/kowari-1.2.0.jar

WEB-INF/lib/mysql-connector-java-3.1.13-bin.jar

WEB-INF/lib/tupelo2.jar

WEB-INF/sun-web.xml

WEB-INF/top.jspf

WEB-INF/web.xml

images/Thumbs.db

images/bg.jpg

images/brain.gif

images/brain_banner.gif

images/ui.gif

index.jsp

relevance.jsp

result.jsp

shmilylemon@yahoo.coma at 2007-7-15 4:57:07 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8

> ItqlInterpreterBean is in the c.jar.What do you

> mean no instances? I am quite a beginner and do not

> quite understand. Besides, b.jar and c.jar actually

> are from others, they are some database connection

> package. I have no access to their source.They do

> have javadoc and I can learn the interface

> information there, though.

>

> Message was edited by:

> shmilylemon@yahoo.com

Check the common/lib and shared/lib directories to make sure that there isn't a copy of b.jar in either.

tolmanka at 2007-7-15 4:57:07 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9
Where is the common/lib and shared/lib? Are they some tomcat setting or java setting?
shmilylemon@yahoo.coma at 2007-7-15 4:57:07 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 10
tomcat - directly below the tomcat install directory.
Madathil_Prasada at 2007-7-15 4:57:07 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 11

It is really odd.I put the one necessary jar file, kowari-1.2.0.jar, in WEB-INF/lib and it keeps give me an exception of "java.lang.NoClassDefFoundError:", which indicate that it cannot find the class. Then I unzip the war file and unzip the jar file into WEB-INF/class and it works. It also works when I put the jar in the common/lib or unzipped class files into common/class.From what I learned from the book and internet all these methods should be equivalent. What is the possible problem?

Is it possible that kowari1.2.0.jar is not well-packed?

shmilylemon@yahoo.coma at 2007-7-15 4:57:07 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 12

> It is really odd.I put the one necessary jar

> file, kowari-1.2.0.jar, in WEB-INF/lib and it keeps

> give me an exception of

> "java.lang.NoClassDefFoundError:", which indicate

> that it cannot find the class. Then I unzip the war

> file and unzip the jar file into WEB-INF/class and it

> works. It also works when I put the jar in the

> common/lib or unzipped class files into common/class.

> From what I learned from the book and internet all

> these methods should be equivalent. What is the

> possible problem?

>

> Is it possible that kowari1.2.0.jar is not

> well-packed?

Then you couldnt have unzipped it.

It probably looks like tomcat has lost the classpath setting to web-inf/lib

Could happen if somebody accidentally edited the server files (setEnv/catalina.bat or something like that) which sets the classpath before starting tomcat.

2 ways to find out

1. Reinstall tomcat and try it out.

2. Put another jar file in web-inf/lib and try accessing one class file from within your code.

cheers,

ram.

Madathil_Prasada at 2007-7-15 4:57:07 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...