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.
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.
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.
> 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.
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.
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
Post your web application folder structure here.
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
> 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.
Where is the common/lib and shared/lib? Are they some tomcat setting or java setting?
tomcat - directly below the tomcat install directory.
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?
> 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.
