Maven Tomcat 嵌入式

6

我正在尝试使用maven运行一个Spring Web应用程序

mvn tomcat:run

每当我导航到http://localhost:8080/myApp时,我会得到错误消息:"所请求的资源()不可用"。日志中没有显示任何内容。 我认为我的应用程序应部署到"/"而不是"/myApp"。 有没有办法做到这一点?
Maven输出日志:
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'tomcat'.
[INFO] ------------------------------------------------------------------------
[INFO] Building myApp
[INFO]    task-segment: [tomcat:run]
[INFO] ------------------------------------------------------------------------
[INFO] Preparing tomcat:run
[INFO] [resources:resources {execution: default-resources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 4 resources
Downloading: http://svn.asdf.com:8081/artifactory/repo/org/postgresql/postgresql/8.3/postgresql-8.3.pom
[INFO] Unable to find resource 'org.postgresql:postgresql:pom:8.3' in repository central (http://repo1.maven.org/maven2)
Downloading: http://svn.asdf.com:8081/artifactory/repo/java-memcached/java-memcached/1.6/java-memcached-1.6.pom
[INFO] Unable to find resource 'java-memcached:java-memcached:pom:1.6' in repository central (http://repo1.maven.org/maven2)
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [tomcat:run {execution: default-cli}]
[INFO] Running war on http://localhost:8080/myApp
[INFO] Using existing Tomcat server configuration at C:\cygwin\home\workspace\myApp\target\tomcat
Sep 4, 2009 3:17:29 PM org.apache.catalina.startup.Embedded start
INFO: Starting tomcat server
Sep 4, 2009 3:17:29 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.16
Sep 4, 2009 3:17:30 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
Sep 4, 2009 3:17:31 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'myApp'
Sep 4, 2009 3:17:31 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Sep 4, 2009 3:17:31 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080

Web.xml:

<?xml version="1.0" encoding="ISO-8859-1"?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
         version="2.4">

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
                /WEB-INF/applicationContext.xml
        </param-value>
    </context-param>

    <servlet>
        <servlet-name>context</servlet-name>
        <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet>
        <servlet-name>myApp</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>3</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>myApp</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

</web-app>

你能发布Maven输出日志吗? - rodrigoap
是pom文件吗?还是web.xml文件?或者是server.xml文件? - Jherico
在我看来很不错。你有查看过Tomcat的日志文件吗? - rodrigoap
1个回答

10

这里的Maven Tomcat插件文档规定了默认上下文路径为/${project.build.finalName},而该属性本身则默认为/${artifactId}-${version}

更改上下文路径的首选方式是通过向pom.xml添加以下内容来更改finalName:

<build>
        <finalName>mycontext</finalName>
</build>

你也可以通过向pom.xml添加一个显式的插件配置块来指定不同的上下文路径,如下所示:

<plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>tomcat-maven-plugin</artifactId>
        <configuration>
                <path>/mycontext</path>
        </configuration>
</plugin>

如果你在pom文件中定义了这两个元素之一,它应该会加载到localhost:8080/wherever。否则它将会在localhost:8080/${artifactId}-${version}上。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接