5

I checked the javadocs of the Tomcat library I have included under my Netbeans project, and when I deploy the code works fine, but when I do a clean-build of my web project I get a "cannot find symbol" on the getContextPath() method of the ServletContext interface

It's driving me completely insane because in order to run my tests and so on I have to first deploy, then test, if I clean and build, or clean and run tests I get this error...

Anyone have any clue what could be causing this issue? Is there a library I have to update or something?

walnutmon
  • 5,873
  • 7
  • 42
  • 57

1 Answers1

7

I suspect it's not in the version of ServletContext you're building against, but it is in the version you're deploying against. According to the docs of version 2.5 it was introduced in 2.5. So basically change the servlet.jar you're building against to be the 2.5 one, and it should be fine.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • For that matter, you need Tomcat 6.x for Servlet 2.5 support. – Powerlord Jun 25 '10 at 19:34
  • Yes, it was working when deploying but not when building.. which doesn't make sense... how does it deploy if it can't build?! Either way, you're right, I had a different servlet.jar in another project that was included... why someone here needed to include servlet.jar in a plain java non-web project... I have no idea – walnutmon Jun 25 '10 at 19:37
  • How does it deploy if it can't build? Your build classpath is probably different than your deploy classpath. In particular the order of things in the classpaths are probably different. – DaBlick Apr 09 '13 at 14:02
  • 1
    If you use GGTS, you could accidentally get an older version of Servlet API through the GROOVY_LIBRARIES container; this will lead to a weird bug where some unit tests will execute fine in maven, but will complain about the missing getServletContext method when executed inside GGTS. This took me two hours to figure it out, hope this helps someone! – Riccardo Cossu Jun 05 '14 at 07:14
  • helped me after removing groovy libraries everything worked fine – Mateen Jan 29 '15 at 06:00