我一直关注来自vogella.com的 Servlet and JSP development with Eclipse WTP 。我已经安装了Tomcat 7,复制粘贴代码(一个简单的数据访问对象和一个简单的HpptServlet),并从eclipse启动服务器。
当我在网络中打开http://localhost:8080/de.vogella.wtp.filecounter/FileCounter
时,预期结果为:
但是我收到了404错误:
此错误记录在控制台中:
Sep 15, 2013 7:27:09 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /Users/adamatan/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
Sep 15, 2013 7:27:09 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:de.vogella.wtp.filecounter' did not find a matching property.
Sep 15, 2013 7:27:09 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Sep 15, 2013 7:27:09 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Sep 15, 2013 7:27:09 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 525 ms
Sep 15, 2013 7:27:09 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Sep 15, 2013 7:27:09 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.42
Sep 15, 2013 7:27:09 PM org.apache.catalina.core.StandardContext resourcesStart
SEVERE: Error starting static Resources
java.lang.IllegalArgumentException: Document base /Users/adamatan/Personal/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/de.vogella.wtp.filecounter does not exist or is not a readable directory
at org.apache.naming.resources.FileDirContext.setDocBase(FileDirContext.java:138)
at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:5055)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5235)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
Sep 15, 2013 7:27:09 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error in resourceStart()
Sep 15, 2013 7:27:09 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error getConfigured
Sep 15, 2013 7:27:09 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/de.vogella.wtp.filecounter] startup failed due to previous errors
Sep 15, 2013 7:27:09 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Sep 15, 2013 7:27:09 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Sep 15, 2013 7:27:09 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 255 ms
相关信息:
catalina run
)运行正常。任何想法为什么tomcat不运行我的简单Servlet?
更新:我正在使用OSX
答案 0 :(得分:2)
我怀疑您使用自己的用户运行tomcat - 这是unix系统中的常见做法 - 并且该用户没有对您的主目录 /Users/adamatan
的读取权限。
然后您可以尝试将tomcat用户添加到您的用户所属的组中。
更好的是尝试按照此so question中的描述将服务器位置更改为eclipse具有写访问权限且tomcat用户具有读访问权限的位置。
修改强>
实际上是Dynamic Web Project
向导中的设置,如果您在第一页上选择Dynamic web module version 3.0
(默认值)或更高,则在最后一页上Generate web.xml deployment descriptor
的复选框被禁用默认情况下。如果选择2.5或更低,则默认启用。它与您实际使用的tomcat无关。如果你想使用注释,那么你必须使用带有servlet规范3.0的tomcat 7
答案 1 :(得分:0)
这是一个Tomcat 6教程,我使用的是Tomcat 7.
Eclipse没有创建web.xml
文件,因为它期待Java代码中的注释。教程代码不包含任何注释,因此服务器在没有servlet的情况下启动。