4

我正在尝试通过在 Tomcat 上运行它来测试我的 servlet。但是,我收到上述错误(有时会发生此错误,但之前 servlet 运行良好)。几个事实:

  1. 我已经彻底查看了这个类似问题的解释,以及这里这里

  2. 当我尝试重新启动 Tomcat(从 Eclipse 的“服务器”选项卡中)时,我从控制台收到一些错误日志:

“严重:无法打开访问日志文件 [~\Tomcat 7.0\logs\localhost_access_log.2012-07-12.txt]”,在日志输出的最后,有“INFO: SessionListener: sessionDestroyed('E9A6117FDF54752D80A1B9B72F2B83D3') -- 在本文底部查看更多信息

  1. 我在“C:\Program Files\Apache Software Foundation\Tomcat 7.0\logs”查看了我的日志文件,并且没有与上面第 (2) 项中的内容相似的文件

  2. 我通过 Eclipse“部署”我的应用程序(也就是说,在开发过程中,我依赖 Eclipse 来启动 Tomcat),只有当我通过将适当的 java 类文件复制到 Tomcat 的 /webapps/ 中获得稳定版本的项目时才进行真正的部署WEB-INF/classes 文件夹并重启 Tomcat

最重要的是,5. 输入“ http://localhost:8080 ”将我带到 Tomcat 主页(所以我很确定服务器正在运行),而“ http://localhost:8080/MyProjectName/MyServlet ”在浏览器中导致显示此问题标题的错误。

有什么想法/帮助吗?非常感谢!

在此处查看更多错误日志

>!Jul 12, 2012 6:18:18 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: C:\Program Files\Java\jdk1.7.0\jre\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre7/bin/client;C:/Program Files/Java/jre7/bin;C:/Program Files/Java/jre7/lib/i386;C:\Users\Kiptoo\introcs\java\bin;C:\Windows\system32;C:\Windows;C:\Windows\system32\wbem;C:\Program Files\MiKTeX 2.8\miktex\bin;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files\Matlab\R2010a\runtime\win32;C:\Program Files\Matlab\R2010a\bin;C:\Program Files\TortoiseSVN\bin;C:\Program Files\QuickTime\QTSystem;C:\Users\Kiptoo\introcs\bin;C:\Users\Kiptoo\introcs\java\bin;C:\Python27;C:\Program Files\Eclipse;;.
Jul 12, 2012 6:18:20 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Jul 12, 2012 6:18:20 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Jul 12, 2012 6:18:20 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 2050 ms
Jul 12, 2012 6:18:20 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Jul 12, 2012 6:18:20 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.25
Jul 12, 2012 6:18:20 PM org.apache.catalina.valves.AccessLogValve open
SEVERE: Failed to open access log file [C:\Program Files\Apache Software Foundation\Tomcat 7.0\logs\localhost_access_log.2012-07-12.txt]
java.io.FileNotFoundException: C:\Program Files\Apache Software Foundation\Tomcat 7.0\logs\localhost_access_log.2012-07-12.txt (Access is denied)
    at java.io.FileOutputStream.open(Native Method)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:212)
    at org.apache.catalina.valves.AccessLogValve.open(AccessLogValve.java:1115)
    at org.apache.catalina.valves.AccessLogValve.startInternal(AccessLogValve.java:1222)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.StandardPipeline.startInternal(StandardPipeline.java:185)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1144)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:782)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1568)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1558)
    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:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)

Jul 12, 2012 6:18:20 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\AndroidTest
Jul 12, 2012 6:18:20 PM org.apache.catalina.core.StandardContext postWorkDirectory
WARNING: Failed to create work directory [C:\Program Files\Apache Software Foundation\Tomcat 7.0\work\Catalina\localhost\AndroidTest] for context [/AndroidTest]
Jul 12, 2012 6:18:21 PM org.apache.catalina.util.SessionIdGenerator createSecureRandom
INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [175] milliseconds.
Jul 12, 2012 6:18:21 PM org.apache.jasper.EmbeddedServletOptions <init>
SEVERE: The scratchDir you specified: C:\Program Files\Apache Software Foundation\Tomcat 7.0\work\Catalina\localhost\AndroidTest is unusable.
Jul 12, 2012 6:18:21 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\docs
Jul 12, 2012 6:18:21 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\examples
Jul 12, 2012 6:18:21 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
Jul 12, 2012 6:18:21 PM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
Jul 12, 2012 6:18:21 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: attributeAdded('org.apache.jasper.compiler.TldLocationsCache', 'org.apache.jasper.compiler.TldLocationsCache@ff8399')
Jul 12, 2012 6:18:21 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\host-manager
Jul 12, 2012 6:18:22 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\manager
Jul 12, 2012 6:18:22 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT
Jul 12, 2012 6:18:22 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Jul 12, 2012 6:18:22 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Jul 12, 2012 6:18:22 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 2225 ms
Jul 12, 2012 6:19:22 PM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: sessionDestroyed('E9A6117FDF54752D80A1B9B72F2B83D3')
4

1 回答 1

3

只有当我有一个稳定版本的项目时才进行真正的部署,方法是将适当的 java 类文件复制到 Tomcat 的 /webapps/WEB-INF/classes 文件夹并重新启动 Tomcat

停在那里:你永远不应该把任何文件放进去webapps/WEB-INF,并期望它会带来任何好处。使用广为接受的打包方式(例如 WAR 文件或分解的 WAR 结构)将您的 webapp 正确部署到 webapps 目录中。

二、问题很明显:java.io.FileNotFoundException: C:\Program Files\Apache Software Foundation\Tomcat 7.0\logs\localhost_access_log.2012-07-12.txt (Access is denied)。您的 Tomcat 无法写入该文件。仅仅因为您是管理员并不意味着 Tomcat 可以写入该目录:据我所知,Tomcat 不能很好地与 UAC 配合使用,而您正在尝试写入Program Files通常需要一些丑陋的 UI 凭据输入 hack。

因此,请检查您的文件(和目录)权限。检查Tomcat进程的uid:确保它们都是好的。最后,考虑使用CATALINA_HOMEand CATALINA_BASE(阅读文档以了解如何做到这一点)来解决您的所有权限问题。

于 2012-07-13T01:28:02.603 回答