facebook

ME 7, Tomcat 6 Classpath Issues

  1. MyEclipse IDE
  2.  > 
  3. Java EE Development (EJB, JSP, Struts, XDoclet, etc.)
Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #294368 Reply

    Adam Hill
    Member

    Hey folks. I feel like I’ve been Googling all day and just chasing my tail. Please help me out if you can.

    It seems like a simple problem but basically it looks like a classpath issue with the embedded (sandbox) Tomcat 6 deployment I’m using with my project. I had a barebones project using Spring 2.5 and Hibernate 3.2 libraries which I was able to deploy to the sandbox and it started up just fine and I could see the “This is my JSP page” page.

    I then wanted to add JSF functionality, so I enabled JSF 1.2 using ME project capabilities and then added RichFaces libraries and a basic faces-context.xml. I now want to just test the baseline config by starting up Tomcat.

    I started out by getting a NullPointerException from Digester but found it was because the xml file (in the RichFaces libraries) was not found on the classpath. This library (and all others needed) were deployed to WEB-INF/lib properly by ME but they are not on the classpath at runtime. I added an external copy of the jar to the Tomcat “append to classpath” area which got rid of the first error and then of course moved on to the next missing class.

    I’d really like to know how ME handles the Tomcat VM classpath. Is it based on what is in my project WEB-INF/lib? Is it based on the build path settings? Are external jars treated differently in the deployment than those in the project’s lib dir? Someone must know b/c someone had to write the code 🙂 I really have tried to find documentation on it to no avail.

    FYI, I have done the usual clean and redeploy of Tomcat and project but no difference.
    THANKS FOR ANY INSIGHT YOU CAN OFFER!

    #294451 Reply

    Riyad Kalla
    Member

    Actually you are doing everything right… the sandbox Tomcat is literally Tomcat 6 — just trimmed down. So anything under your WEB-INF/lib is loaded… NOTE: Any time there is a conflict with a server-provided library, the server library takes precedence… so my guess is that all the JARs and classes that are “missing” from your running application, actually conflicted on-load with Tomcat ones and weren’t loaded.

    Nomrally application servers have a setting to tell the app server to prefer the server libs or the web app libs to correct these conflicts, I’m not sure what the command is in Tomcat, but you might do a standalone install of Tomcat 6 to work with if you need to tweak out the server.

    NOTE: That’s as easy as downloading the ZIP, unzipping it, and pointing MyEclipse’s Tomcat 6 connector at it, no need to run the EXE installer.

    #294652 Reply

    Adam Hill
    Member

    Thanks for the info. From further reading I agree that anything in WEB-INF/lib should be loaded automatically by Tomcat. However, I’ve found that if I use ME out of the box, I get an error because it can’t find an XML file that resides inside a JAR file in WEB-INF/lib. So, then I change the Tomcat settings in ME to append that one JAR file (the RichFaces impl jar) and that error goes away and is replaced by the next class it can’t find (in another RichFaces JAR sitting in WEB-INF/lib).

    Since the RichFaces libraries should have no interference with Tomcat libs, I don’t know why they wouldn’t be loaded. However, the problem doesn’t stop there. In desperation, I can manually add ALL of the JARs in WEB-INF/lib to the classpath and I’m left with the following:

    java.lang.NoClassDefFoundError: javax/servlet/ServletRequestListener

    Let me know if you have any ideas of how I might be screwing this up 🙂 Thanks!

    Adam

    #294709 Reply

    Riyad Kalla
    Member

    Adam, this behavior is all normal “Server library conflict” errors — note you might not be seeing the XML in your JAR, not because of RichFaces, but because you might be trying to deploy a conflicting XML parsing JAR… and so you fixed that, and now it looks like you are deploying the JavaEE libs which are *all* conflicting with the Tomcat-provided ones and now you cannot even get basic servlet initialization going.

    I would suggest googling for how other folsk are solving this with RichFaces and Tomcat.

    #294753 Reply

    Adam Hill
    Member

    Thanks again. I’m understanding more now but lets focus on this one problem and maybe you can tell me how best to resolve the conflicts and I can apply it to the remaining issues. You are right that multiple Digester (XML parser) classes are being loaded and here is where they are found:

    CATALINA_HOME\lib\tomcat_coyote.jar => org/apache/tomcat/util/digester
    <app>\WEB_INF\lib\commons-digester-2.0.jar => org/apache/commons/digester
    <app>\WEB_INF\lib\jsf-impl.jar => com/sun/org/apache/commons/digester

    Now, I can get rid of commons-digester-2.0.jar and have done that but still get the error. As far as I know, I can’t get by without jsf-impl.jar b/c the JSF classes are not included in Tomcat 6 or RichFaces. How then do I avoid a conflict or at least instruct Tomcat as to which one to use, other than doing what I already did in manually adding the jars from WEB-INF/lib?

    Incidentally, regarding the JavaEE libs, I’ve found no conflicts between Tomcat and the libs I’m deploying. Servlet-api.jar is in CATALINA_HOME/lib and there are no other versions anywhere else and I’ve gone through all JARS and can find no duplicate instances of javax/servlet/ServletRequestListener.

    I appreciate your advice and apologize if I seem green on this but I am pretty new to Tomcat web app deployments. In between posts I am Googling my brains out but can’t seem to find others having the same errors with conflicting libs. Here is someone’s example of RichFaces with tomcat 6 and he’s got both of the same Digester-including JARs that I have but supposedly his works. 🙁 http://www.jsfone.com/blog/max_katz/2008/07/richfaces_with_tomcat_6.html

    #294881 Reply

    Riyad Kalla
    Member

    Now, I can get rid of commons-digester-2.0.jar and have done that but still get the error. As far as I know, I can’t get by without jsf-impl.jar b/c the JSF classes are not included in Tomcat 6 or RichFaces. How then do I avoid a conflict or at least instruct Tomcat as to which one to use, other than doing what I already did in manually adding the jars from WEB-INF/lib?

    Actually you might *not* be able to get rid of the other copy of Digester — the solution to this whole mess is to dig into the Tomcat docs and figure out the entry in the server.xml you have to add to tell the server to *prefer* the web-apps own classes over it’s server-provided ones… these conflicts aren’t new to Tomcat, they happen like crazy on JBoss and other app-servers that tend to ship a ton of community-popular JARs.

    I appreciate your advice and apologize if I seem green on this but I am pretty new to Tomcat web app deployments. In between posts I am Googling my brains out but can’t seem to find others having the same errors with conflicting libs. Here is someone’s example of RichFaces with tomcat 6 and he’s got both of the same Digester-including JARs that I have but supposedly his works. 🙁 http://www.jsfone.com/blog/max_katz/2008/07/richfaces_with_tomcat_6.html

    Did you dig into his example app and see if he omits any libraries from the final deployment? Maybe you guys are using different versions of Tomcat? Very strange…

    #294927 Reply

    Adam Hill
    Member

    Thanks, I’ll keep looking. I may use that example project as a jumping off point and see when it breaks. Anyways, I looked at the Tomcat 6 configuration reference and it seems like the default is to look at the web app’s jars first. Let me know if I’m reading this wrong:

    (‘delegate’ attribute of the ‘Loader’ component)
    Set to true if you want the class loader to follow the standard Java2 delegation model, and attempt to load classes from parent class loaders before looking inside the web application. Set to false (the default) to have the class loader look inside the web application first, before asking parent class loaders to find requested classes or resources.

    http://tomcat.apache.org/tomcat-6.0-doc/config/loader.html

    Thanks again. I’ll let you know if I have any revelations 🙂
    Adam

    #295011 Reply

    Riyad Kalla
    Member

    Curses! Yes you read that exactly right, looks like the default is what we want… I’m seriously bamboozled by this.

    #295021 Reply

    Adam Hill
    Member

    Well, I basically started over using the richfaces-tomcat6 example as a jumping off point and I’ve got a working app now. I’m writing off the last attempt as a failure and moving forward. 🙂

    I do have one final question regarding something I mentioned earlier. I’m trying to figure out how to get MyEclipse to include an external JAR file at build time but not in the deployment. For example, I needed the servlet API available to validate some of my classes but this is already included in Tomcat 6 so I don’t want the JAR file deployed to WEB-INF/lib. However, if I simply add the JAR (from an external directory) to the build path, it is automatically deployed and I see a warning about it when I start up Tomcat. Can you tell me the proper way to do this in ME?

    Thanks again! ~Adam

    #295059 Reply

    Loyal Water
    Member

    I do have one final question regarding something I mentioned earlier. I’m trying to figure out how to get MyEclipse to include an external JAR file at build time but not in the deployment. For example, I needed the servlet API available to validate some of my classes but this is already included in Tomcat 6 so I don’t want the JAR file deployed to WEB-INF/lib. However, if I simply add the JAR (from an external directory) to the build path, it is automatically deployed and I see a warning about it when I start up Tomcat. Can you tell me the proper way to do this in ME?

    You can create a new user library with these jars and add the user library to the project build path. Now go to Windows > Prefs > MyEclipse > Java Enterprise Project > Web Project > Deployment and uncheck the option that says “Jars from user libraries” under the Library Deployment Policies.

    This should prevent the libs from getting deployed.

Viewing 10 posts - 1 through 10 (of 10 total)
Reply To: ME 7, Tomcat 6 Classpath Issues

You must be logged in to post in the forum log in