Why can't Tomcat / JSP see these classes?

I am trying to write a web application using JSP and Java on Tomcat 7.0.14, and part of it is connected to connecting to a MySQL server using Hibernate .

Here is the basic view of my directory structure:

apache-tomcat-7.0.14 |- webapps |- ROOT |- WEB-INF | |- classes | | |- some-package-path | | \- foo.java | | \- foo.class | |- lib | \- hibernate3.jar \- file_giving_issues.jsp 

Now "file_giving_issues.jsp", as you might have guessed, is a file that gives me problems. It cannot see the classes contained in various jibernate jar files. I used the following instruction:

 <%@ page import="org.hibernate.Session" %> 

Here, Tomcat tells me

 Only a type can be imported. org.hibernate.Session resolves to a package. 

This, by the way, is not true; A session is definitely a type, not a package, and in it hibernate3.jar . More specifically, it exists here:

 WEB-INF/lib/hibernate3.jar/org/hibernate/Session.class 

But I decided that I would play the ball and just import everything from org.hibernate, for example:

 <%@ page import="org.hibernate.*" %> 

Even more incomprehensible, Tomcat now tells me

 Session cannot be resolved to a type. 

So, I lost a little. I'm not sure if this is a problem with setting up Tomcat or with my class directory structures, or if I don’t understand how JARs work or what. As far as I understand, JAR files in WEB-INF / lib should always be on the Tomcat Classpath, and these files in WEB-INF / classes / some-package-paths work fine, so I get lost.

Any help would be appreciated.

+4
source share
2 answers
 Only a type can be imported. XXXXX resolves to a package. 

The above usually means that the container cannot find the class file.

Can you find out if you can import other banks or classes? I mean, debug; create a simple JSP welcome world and import some of your custom classes and see if you can work with it.

Also make sure that the Session class is indeed present in one of the jars of your lib directory.

0
source

Do you have any other JAR files in WEB-INF / lib except sleep mode? I had a similar problem: tomcat did not see the JAR in WEB-INF / lib, but worked perfectly with the same files in the global lib directory.

In my case, I deleted some unused obsolete files from WEB-INF / lib and it suddenly started working.
It seems that tomcat will not load some files from WEB-INF / lib (for example, it complains about any file using the javax.servlet classes) and silently ignores others.

0
source

All Articles