当前位置:  开发笔记 > 编程语言 > 正文

Maven Tomcat Embedded

如何解决《MavenTomcatEmbedded》经验,为你挑选了1个好方法。

我正在尝试使用maven运行Spring webapp

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中:





    
        contextConfigLocation
        
                /WEB-INF/applicationContext.xml
        
    

    
        context
        org.springframework.web.context.ContextLoaderServlet
        1
    

    
        myApp
        org.springframework.web.servlet.DispatcherServlet
        3
    
    
        myApp
        /*
    


whaley.. 10

maven tomcat插件的文档在此处说明了默认的上下文路径/${project.build.finalName},它本身默认为/${artifactId}-${version}.

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


        mycontext

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


        org.codehaus.mojo
        tomcat-maven-plugin
        
                /mycontext
        

如果你在pom中定义了这两个元素中的任何一个,那么它应该在localhost:8080/wherever加载.否则它会在localhost:8080/${artifactId}-${version}



1> whaley..:

maven tomcat插件的文档在此处说明了默认的上下文路径/${project.build.finalName},它本身默认为/${artifactId}-${version}.

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


        mycontext

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


        org.codehaus.mojo
        tomcat-maven-plugin
        
                /mycontext
        

如果你在pom中定义了这两个元素中的任何一个,那么它应该在localhost:8080/wherever加载.否则它会在localhost:8080/${artifactId}-${version}

推荐阅读
U友50081205_653
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有