Я пытаюсь создать базовый сервлет с eclipse helios ee и tomcat 7. Я вижу, что tomcat работает нормально, потому что я могу запустить сервер из eclipse, наведите мой браузер на localhost: 8080 и он получит страница приветствия.
Итак, я создал сервлет с мастером динамических веб-проектов, но я получаю 404 при попытке его просмотреть. Я также вижу, что для него нет файла web.xml в каталоге WEB-INF. Должно ли затмение создавать это автоматически или это то, что я должен сделать? Во всех уроках, которые я видел, кажется, что web.xml создается автоматически?
Спасибо за вашу помощь - извините, вопрос немного расплывчатый - я не совсем уверен, с чего начать поиск решения ..
Спасибо!
EDIT:
Я попытался создать файл web.xml вручную. Я вижу, что сервер находится в нужном месте (я думаю), чтобы увидеть его:
/ Пользователи / мт / Документы / workspace2 / .metadata / .plugins / org.eclipse.wst.server.core / tmp0 / wtpwebapps / HelloWorld / WEB-INF / web.xml
и файл выглядит так:
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" version="2.4"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http:/java.sun.com/dtd/web-app_2_3.dtd">
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>mytest.HelloWorld</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
</web-app>
EDIT:
Бревно Каталины выглядит так:
Jun 1, 2011 11:37:56 AM 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: .:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java
Jun 1, 2011 11:37:56 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:HelloWorld' did not find a matching property.
Jun 1, 2011 11:37:56 AM org.apache.coyote.AbstractProtocolHandler init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Jun 1, 2011 11:37:56 AM org.apache.coyote.AbstractProtocolHandler init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Jun 1, 2011 11:37:56 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1154 ms
Jun 1, 2011 11:37:56 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Jun 1, 2011 11:37:56 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.14
Jun 1, 2011 11:37:57 AM org.apache.coyote.AbstractProtocolHandler start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Jun 1, 2011 11:37:57 AM org.apache.coyote.AbstractProtocolHandler start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Jun 1, 2011 11:37:57 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 583 ms
EDIT:
Попробовал удалить приложение с сервера и получил это:
Jun 1, 2011 12:03:28 PM org.apache.catalina.loader.WebappClassLoader modified
SEVERE: Resource '/WEB-INF/classes/mytest/HelloWorld.class' is missing Jun 1, 2011 12:03:28 PM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/HelloWorld] has started
Jun 1, 2011 12:03:29 PM org.apache.catalina.core.StandardContext resourcesStart
SEVERE: Error starting static Resources
java.lang.IllegalArgumentException: Document base /Users/bw/Documents/workspace2/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/HelloWorld does not exist or is not a readable directory
at org.apache.naming.resources.FileDirContext.setDocBase(FileDirContext.java:140)
at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:4836)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5016)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3854)
at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:424)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1205)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1391)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1401)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1401)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1380)
at java.lang.Thread.run(Thread.java:637)
Jun 1, 2011 12:03:29 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error in resourceStart()
Jun 1, 2011 12:03:29 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error getConfigured
Jun 1, 2011 12:03:29 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/HelloWorld] startup failed due to previous errors
Jun 1, 2011 12:03:29 PM org.apache.catalina.util.LifecycleBase stop
INFO: The stop() method was called on component [Pipeline[StandardEngine[Catalina].StandardHost[localhost].StandardContext[/HelloWorld]]] after stop() had already been called. The second call will be ignored.
Jun 1, 2011 12:03:29 PM org.apache.catalina.util.LifecycleBase stop
INFO: The stop() method was called on component [WebappLoader[/HelloWorld]] after stop() had already been called. The second call will be ignored.
Jun 1, 2011 12:03:29 PM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/HelloWorld] is completed
Похоже, классы не копируются из каталога сборки в область сервера?
EDIT:
AHA! Наконец-то нашел проблему. Ну, возможно, было несколько вещей.
1) Я попытался удалить сервер, а затем создать новый и добавить сервлет. Похоже, что он запутался и не скопировал необходимые файлы в область сервера.
2) Затмение дало мне неправильный URL для просмотра сервлета. Я смотрел на / hello, и мне нужно было посмотреть на HelloWorld / hello - похоже, что Eclipse не включает контекст, когда предлагает URL для сервлета?
Я отправлю ответ, когда у меня будет более четкое представление о том, что идет не так ..
Спасибо всем за помощь!