问题
I did Ctrl+Click on HttpServlet
to see source code of HttpServlet
, but it gave me this error:
How to fix this? It says, I should download "servlet-api.jar", but when I try to download, I can not understand which one should I download? There are lot of servlet-api.jar files.
回答1:
The source code is not necessarily specific to the Servlet API, but to the Servlet Implementation itself. In your particular case, Tomcat is the Servlet Implementation. So, you need to head to its homepage to find download links to the source code. Usually it's at the same place as where you downloaded the binaries.
Tomcat 8.0 download page is here, if you scroll to bottom, then you should see those links:
Binary Distributions
- Core:
- zip <-- this is Tomcat server itself.
- ...
Source Code Distributions
- ...
- zip <-- this contains the source code.
Download the source code zip, put it somewhere in your file system (I usually put it in Tomcat installation folder; do note that you do not need to extract it!). Finally, press Attach Source button in Eclipse and point to that source code zip file.
回答2:
If this maven based project , you just select the dependency in the Package Explorer, right click and then select "Attach resource"
来源:https://stackoverflow.com/questions/35713815/the-jar-file-c-tomcat-8-0-lib-servlet-api-jar-has-no-source-attachment