开发者

Maven's tomcat:run mojo doesn't see my servlet

I have a simple WAR project managed by Maven. I have the servlet code under src/main/java/* and all the static content (HTML, images, etc) under src/main/webapp. I can deploy the resulting WAR on our staging JBoss server and it works, but the round-trip to redeploy is painfully slow. I'd like to be able to test changes locally on an embedded Tomcat, but I'm having problems.

The servlet mapping is set up in src/main/resources/web.xml -- I think it's correct; the relevant part looks like

<servlet>
  <servlet-name>myServ</servlet-name>
  <servlet-class>my.pkg.MyServ</servlet-class>
</servlet>

<servlet-mapping>
  <servlet-name>myServ</servlet-name>
  <url-pattern>/ms</url-pattern>
</servlet-mapping>

Maven tells me it's running at localhost:8080/myprojectname, and indeed when I go there I can see the static content. However, I've tried localhost:8080/myprojectname/ms as well as ``localhost:8080/ms` -- the former gives me a 404, and the latter a 0-byte response.

In short: where's my active content? I see nothing on the console. It looks like Maven made a target/tomcat/logs but that's empty. target/tomcat/webapps is empty too, and when I run mvn tomcat:run -X, I get a lot of debug output, including references to all my JAR dependencies, a classesDir property that points to target/classes (which is correct), but no mention anywhere of that URL pattern I set, nor the name of the Servlet class to invoke as a handler. I feel like I'm supposed to tell Maven or Tomcat how to find the web.xml, or maybe specify the URL mapping in another way.... in case you can't tell, I'm new at this :D

ETA: My setup loo开发者_高级运维ks an awful lot like this guy, though our problems appear to be different.


Simpler than I thought: though the POM is set up to use src/main/resources/web.xml, that's not the "right" place to put it. Moving it to src/main/webapp/META-INF made the servlet show up -- which, of course, led to another dozen or so mistakes in the project settings, but that's a story for another day.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜