6 Replies Latest reply on Jun 26, 2003 1:13 PM by David P.

    JSP Classpath compilation problems

    Nathaniel Stoddard Newbie

      Hi folks -- I'm having a problem compiling some jsp files and I can't for the life of me figure out what the heck I need to do to make it work.

      The problem is that my jboss-jetty compiler won't compile my jsp file because it claims it can't resolve certain symbols. The sad thing is, it doesn't seem to resolve any symbols.

      I have my app all cooly ear'ed up with my war in there and all that stuff. It does deploy, and other parts of it work so that's not a problem. In the log file after it croaks trying to compile my jsp file, it does list the jar file I place in the WEB-INF/lib directory as well as alot of other stuff as being on the classpath when it tries to compile. But nada ....

      Oh, I've even tried compiling silly simple things. It refuses to find definitions for simple things like Hashtable and PrintWriter.

      So, please help :)

      To answer the inevitable newbie-esque targeted question, yes I do have the appropriate <jsp:declaration.page import="..."/> in my jsp file. Oh, and yes the java sdk (1.4.1 or whatever it is now) is on my path. I don't know if this matters, but I am doing this on a WinXP.

      Any help would be wonderful

        • 1. Re: JSP Classpath compilation problems
          David P. Newbie

          <%@ page import="HelloWorld" %>

          Gets the same type of error for me - where the JSP compiler can't find the referenced servlet class (which is in the same directory as the JSP - inside the WAR file). I'm running JBoss 3.x with Jetty under Windows XP.

          I am able to include things from the JSDK, like:

          <%@ page import="java.util.*" %>

          with no errors.

          I can't find any documentation on where the JSP compiler gets its classpath from. It doesn't appear to be in any of the configuration XML files that I can find...


          Anyone know how to compile a JSP that can import a servlet class? Thanks!

          Did you ever get your problem solved? What did you have to do to fix it?

          • 2. Re: JSP Classpath compilation problems
            Jon Barnett Master

            I'm not sure what you are actually attempting to achieve with this. If you want to "inline" the output of a servlet in your JSP's output stream, the construct is:

            <jsp:include page="HelloWorld" flush="true"/>

            Your mapping in the WEB-INF/web.xml of your WAR would be:


            <servlet-name>HelloWorldServlet</servlet-name>
            <servlet-class>com.amity.demo.servlet.HelloWorldServlet</servlet-class>


            <servlet-mapping>
            <servlet-name>HelloWorldServlet</servlet-name>
            <url-pattern>/HelloWorld</url-pattern>
            </servlet-mapping>

            HelloWorldServlet.class lives in WEB-INF/classes/com/amity/demo/servlet of the WAR.

            The JSP should not be in the same directory as the servlet as classes and jars live in directories under the special WEB-INF directory of the WAR.

            If you really want to import the servlet class, the servlet must be located in the structure as described by this example.

            Hope that helps.

            • 3. Re: JSP Classpath compilation problems
              Jon Barnett Master

              I'm not sure what you are actually attempting to achieve with this. If you want to "inline" the output of a servlet in your JSP's output stream, the construct is:

              <jsp:include page="HelloWorld" flush="true"/>

              Your mapping in the WEB-INF/web.xml of your WAR would be:


              <servlet-name>HelloWorldServlet</servlet-name>
              <servlet-class>com.amity.demo.servlet.HelloWorldServlet</servlet-class>


              <servlet-mapping>
              <servlet-name>HelloWorldServlet</servlet-name>
              <url-pattern>/HelloWorld</url-pattern>
              </servlet-mapping>

              HelloWorldServlet.class lives in WEB-INF/classes/com/amity/demo/servlet of the WAR.

              The JSP should not be in the same directory as the servlet as classes and jars live in directories under the special WEB-INF directory of the WAR.

              If you really want to import the servlet class, the servlet must be located in the structure as described by this example.

              Hope that helps.

              • 4. Re: JSP Classpath compilation problems
                David P. Newbie

                Thanks for your reply!

                My JSP is trying to call a static method in my servlet, not trying to include the servlet's normal output stream. For this purpose, the class that my JSP is trying to call doesn't even have to be a servlet - it just is one in the case of my example. The more general question is "How can a JSP call a separately compiled Java class, within the JBoss/Jetty environment?".

                In my example, I have the HelloWorld servlet deployed in my WAR file that also contains a Java class named "Hello2" and my "test2.jsp". The HelloWorld servlet is set up with the web.xml file like you describe, and when invoked is able to call methods in the Hello2 class (that itself is not listed at all in the web.xml file, as it is just a class not a servlet).

                The basic problem is that the JSP compiler can't seem to find HelloWorld when it compiles my (test2.jsp) page... Both the JSP page and the class (servlet) that I'm trying to call are packaged in the same WAR file.

                I've tried a few different ways of specifying the name in the page import statement (besides the one I listed above, which worked in other web server environments), looked for any parameters to specify the JSP compiler's classpath, and even tried pointing the system classpath variable to where HelloWorld is - but the JSP compiler still can't resolve it...

                I'm sure this is something simple, but so far I don't know enough to get past this problem... Anyone have a simple example of calling a method in a class or servlet from a JSP page?

                • 5. Re: JSP Classpath compilation problems
                  Jon Barnett Master

                  OK. Well, the advice still holds. Classes or libraries need to reside in the right place within the WAR or placed in the container shared library directories.

                  Suppose I have the following JSP fragment:
                  <%@page contentType="text/html"
                  import="javax.servlet.RequestDispatcher,
                  com.amity.flexweb.MenuSystem"%><%
                  // Check that we have initialised state otherwise invalidate
                  RequestDispatcher dispatcher = request.getRequestDispatcher(State.INVALID);
                  MenuSystem menu = null;
                  if (session != null)
                  menu = (MenuSystem)session.getAttribute(Constants.MENU);%>

                  For the servlet container embedded in JBoss to pick up com.amity.flexweb.MenuSystem, the class can be in one of the following places:
                  1) It can be in any of the lib directories within the scope of the JBoss instance, packaged within a JAR - in the case of the default instance, this means lib or server/default/lib
                  2) In the main directory of jbossweb-jetty.sar or jbossweb-tomcat.sar, packaged within a JAR - in the case of the default instance, this means server/default/deploy/jbossweb-jetty.sar or server/default/deploy/jbossweb-tomcat.sar depending on your embedded servlet container
                  3) It can be in the WEB-INF/lib directory of your WAR, packaged within a JAR
                  4) It can be in the WEB-INF/classes directory as a class, having the correct, directory nesting for the fully qualified class name

                  So if in a WAR, packaged within say the JAR, myutils.jar, the location is:
                  WAR
                  +-- WEB-INF
                  | +-- lib
                  | +-- myutils.jar

                  If in a WAR, as the class com.amity.flexweb.MenuSystem.class, the location is:
                  WAR
                  +-- WEB-INF
                  | +-- classes
                  | +-- com
                  | +-- amity
                  | +-- flexweb
                  | +-- MenuSystem.class

                  That's all that is needed.

                  • 6. Re: JSP Classpath compilation problems
                    David P. Newbie

                    Thanks again for your through explanation!

                    I realized this morning that the error I was getting from my JSP compile wasn't actually a result of it not finding the imported class. It seemed to be the fact that the class I was importing was not part of a package (i.e. just an isolated class). The JSP error message even said something about expecting a "." but I just didn't realize that was most of what it was complaining about.

                    Someone here suggested to me yesterday that JDK1.4 behaved differently with unpackaged classes than earlier versions, which may have contributed to the compile error... Unfortuniately, the Eclipse IDE I've been using won't let you change the package of a class easily, so I had to set up a new project to try that out.

                    My exaple servlet and JSP are now each able to successfully call my support class (which is now in a package, but remains not a servlet per say)! I wasn't able to get the servlet to work if I tried to put that in a package, but it was probably something I was doing wrong in ANT. (It took me about 6 hours this morning, messing around with ANT (tiral and error) to get everything finally working)...

                    I ran into one interesting "feature" when I deployed my support class as part of the new web application I created. JBoss/Jetty served up the older version of it from one of my previous project directories - leading to some confusion on my part about why code changes I made to it didn't show up. I wasn't sure if each web app was supposed to have its own name space or not.

                    Thanks again for all your help! - Dave