Tomcat部署时war和war exploded区别以及平时踩得坑

war和war exploded的区别

在使用IDEA开发项目的时候,部署Tomcat的时候通常会出现下边的情况:

这里写图片描述

是选择war还是war exploded 这里首先看一下他们两个的区别:

war模式:将WEB工程以包的形式上传到服务器 ;
war exploded模式:将WEB工程以当前文件夹的位置关系上传到服务器;

(1)war模式这种可以称之为是发布模式,看名字也知道,这是先打成war包,再发布;

(2)war exploded模式是直接把文件夹、jsp页面 、classes等等移到Tomcat 部署文件夹里面,进行加载部署。因此这种方式支持热部署,一般在开发的时候也是用这种方式。

(3)在平时开发的时候,使用热部署的话,应该对Tomcat进行相应的设置,这样的话修改的jsp界面什么的东西才可以及时的显示出来。

这里写图片描述

修改箭头指向的位置,这样的话就可以实现热部署。

使用war模式开发的时候遇到的坑

一、项目代码的位置如下:

这里写图片描述

上述项目为SSM项目。

二、部署使用的Tomcat位置:

这里写图片描述

三、用于获取上下文环境绝对路径的代码:

String contextPath = request.getSession().getServletContext().getRealPath("/");

四、两种方式的实验过程和结果:

(1)在使用war模式开发的时候,通过下边这段代码获取项目的相对路径:

String contextPath = request.getSession().getServletContext().getRealPath("/");

war模式始终是获取到的路径如下:

这里写图片描述

其中C:\Software\apache-tomcat-8.0.32 是我Tomcat的所在位置。

可以看出通过war模式是最终打包部署到Tomcat的位置。

(2)然后再看war exploded模式,同样进行设置,运行同一段代码,运行结果如下:

这里写图片描述

可以看出最终得到的是我这个项目的位置,其实就是这个项目target的位置。

五、总结

根据上述(1)(2)的实验结果可以看到这两种方式得部署方式是不一样的,因此在获取项目的相对路径的时候得到的结果是不一样的。

[INFO] Scanning for projects... [WARNING] [WARNING] Some problems were encountered while building the effective model for com.taotao:mytaotao-search-service:war:0.0.1-SNAPSHOT [WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.apache.zookeeper:zookeeper:jar -> duplicate declaration of version (?) @ com.taotao:mytaotao-search-service:[unknown-version], D:\develop\DevWorkSpace\myworkspace\mytaotao-search\mytaotao-search-service\pom.xml, line 76, column 15 [WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: com.github.sgroschupf:zkclient:jar -> duplicate declaration of version (?) @ com.taotao:mytaotao-search-service:[unknown-version], D:\develop\DevWorkSpace\myworkspace\mytaotao-search\mytaotao-search-service\pom.xml, line 80, column 15 [WARNING] [WARNING] It is highly recommended to fix these problems because they threaten the stability of your build. [WARNING] [WARNING] For this reason, future Maven versions might no longer support building such malformed projects. [WARNING] [INFO] ------------------------------------------------------------------------ [INFO] Reactor Build Order: [INFO] [INFO] mytaotao-search [INFO] mytaotao-search-interface [INFO] mytaotao-search-service [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building mytaotao-search 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ mytaotao-search --- [INFO] [INFO] >>> tomcat7-maven-plugin:2.2:run (default-cli) > process-classes @ mytaotao-search >>> [INFO] [INFO] <<< tomcat7-maven-plugin:2.2:run (default-cli) < process-classes @ mytaotao-search <<< [INFO] [INFO] --- tomcat7-maven-plugin:2.2:run (default-cli) @ mytaotao-search --- [INFO] Skipping non-war project [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building mytaotao-search-interface 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ mytaotao-search-interface --- [INFO] Deleting D:\develop\DevWorkSpace\myworkspace\mytaotao-search\mytaotao-search-interface\target [INFO] [INFO] >>> tomcat7-maven-plugin:2.2:run (default-cli) > process-classes @ mytaotao-search-interface >>> [INFO] [INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ mytaotao-search-interface --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 0 resource [INFO] [INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ mytaotao-search-interface --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 3 source files to D:\develop\DevWorkSpace\myworkspace\mytaotao-search\mytaotao-search-interface\target\classes [INFO] [INFO] <<< tomcat7-maven-plugin:2.2:run (default-cli) < process-classes @ mytaotao-search-interface <<< [INFO] [INFO] --- tomcat7-maven-plugin:2.2:run (default-cli) @ mytaotao-search-interface --- [INFO] Skipping non-war project [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building mytaotao-search-service 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ mytaotao-search-service --- [INFO] Deleting D:\develop\DevWorkSpace\myworkspace\mytaotao-search\mytaotao-search-service\target [INFO] ------------------------------------------------------------------------ [INFO] Reactor Summary: [INFO] [INFO] mytaotao-search .................................... SUCCESS [ 1.731 s] [INFO] mytaotao-search-interface .......................... SUCCESS [ 1.385 s] [INFO] mytaotao-search-service ............................ FAILURE [ 1.457 s] [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 5.198 s [INFO] Finished at: 2017-06-22T21:15:09+08:00 [INFO] Final Memory: 17M/170M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.5:clean (default-clean) on project mytaotao-search-service: Failed to clean project: Failed to delete D:\develop\DevWorkSpace\myworkspace\mytaotao-search\mytaotao-search-service\target\tomcat\conf\logging.properties -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException [ERROR] [ERROR] After correcting the problems, you can resume the build with the command [ERROR] mvn <goals> -rf :mytaotao-search-service
[INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------ [INFO] Reactor Build Order: [INFO] [INFO] taotao-manager [INFO] taotao-manager-pojo [INFO] taotao-manager-mapper [INFO] taotao-manager-service [INFO] taotao-manager-web [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building taotao-manager 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ taotao-manager --- [INFO] [INFO] >>> tomcat7-maven-plugin:2.2:run (default-cli) > process-classes @ taotao-manager >>> [INFO] [INFO] <<< tomcat7-maven-plugin:2.2:run (default-cli) < process-classes @ taotao-manager <<< [INFO] [INFO] --- tomcat7-maven-plugin:2.2:run (default-cli) @ taotao-manager --- [INFO] Skipping non-war project [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building taotao-manager-pojo 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ taotao-manager-pojo --- [INFO] Deleting C:\ec\taotao-manager\taotao-manager-pojo\target [INFO] [INFO] >>> tomcat7-maven-plugin:2.2:run (default-cli) > process-classes @ taotao-manager-pojo >>> [INFO] [INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ taotao-manager-pojo --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 0 resource [INFO] [INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ taotao-manager-pojo --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] <<< tomcat7-maven-plugin:2.2:run (default-cli) < process-classes @ taotao-manager-pojo <<< [INFO] [INFO] --- tomcat7-maven-plugin:2.2:run (default-cli) @ taotao-manager-pojo --- [INFO] Skipping non-war project [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building taotao-manager-mapper 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ taotao-manager-mapper --- [INFO] Deleting C:\ec\taotao-manager\taotao-manager-mapper\target [INFO] [INFO] >>> tomcat7-maven-plugin:2.2:run (default-cli) > process-classes @ taotao-manager-mapper >>> [INFO] [INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ taotao-manager-mapper --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 0 resource [INFO] [INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ taotao-manager-mapper --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] <<< tomcat7-maven-plugin:2.2:run (default-cli) < process-classes @ taotao-manager-mapper <<< [INFO] [INFO] --- tomcat7-maven-plugin:2.2:run (default-cli) @ taotao-manager-mapper --- [INFO] Skipping non-war project [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building taotao-manager-service 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ taotao-manager-service --- [INFO] Deleting C:\ec\taotao-manager\taotao-manager-service\target [INFO] [INFO] >>> tomcat7-maven-plugin:2.2:run (default-cli) > process-classes @ taotao-manager-service >>> [INFO] [INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ taotao-manager-service --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 0 resource [INFO] [INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ taotao-manager-service --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] <<< tomcat7-maven-plugin:2.2:run (default-cli) < process-classes @ taotao-manager-service <<< [INFO] [INFO] --- tomcat7-maven-plugin:2.2:run (default-cli) @ taotao-manager-service --- [INFO] Skipping non-war project [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building taotao-manager-web 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ taotao-manager-web --- [INFO] Deleting C:\ec\taotao-manager\taotao-manager-web\target [INFO] ------------------------------------------------------------------------ [INFO] Reactor Summary: [INFO] [INFO] taotao-manager ..................................... SUCCESS [ 1.652 s] [INFO] taotao-manager-pojo ................................ SUCCESS [ 0.972 s] [INFO] taotao-manager-mapper .............................. SUCCESS [ 0.277 s] [INFO] taotao-manager-service ............................. SUCCESS [ 0.323 s] [INFO] taotao-manager-web ................................. FAILURE [ 1.283 s] [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 4.948 s [INFO] Finished at: 2016-07-28T14:26:36+08:00 [INFO] Final Memory: 10M/24M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.5:clean (default-clean) on project taotao-manager-web: Failed to clean project: Failed to delete C:\ec\taotao-manager\taotao-manager-web\target\tomcat\logs\access_log.2016-07-28 -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException [ERROR] [ERROR] After correcting the problems, you can resume the build with the command [ERROR] mvn <goals> -rf :taotao-manager-web
INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------ [INFO] Reactor Build Order: [INFO] [INFO] xzytaotao-manager [INFO] xzytaotao-manager-pojo [INFO] xzytaotao-manager-dao [INFO] xzytaotao-manager-service [INFO] xzytaotao-manager-web [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building xzytaotao-manager 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ xzytaotao-manager --- [INFO] [INFO] >>> tomcat7-maven-plugin:2.2:run (default-cli) @ xzytaotao-manager >>> [INFO] [INFO] <<< tomcat7-maven-plugin:2.2:run (default-cli) @ xzytaotao-manager <<< [INFO] [INFO] --- tomcat7-maven-plugin:2.2:run (default-cli) @ xzytaotao-manager --- [INFO] Skipping non-war project [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building xzytaotao-manager-pojo 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ xzytaotao-manager-pojo --- [INFO] Deleting M:\Myeclipseworkspaces\xzytaotao-manager\xzytaotao-manager-pojo\target [INFO] [INFO] >>> tomcat7-maven-plugin:2.2:run (default-cli) @ xzytaotao-manager-pojo >>> [INFO] [INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ xzytaotao-manager-pojo --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 0 resource [INFO] [INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ xzytaotao-manager-pojo --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 22 source files to M:\Myeclipseworkspaces\xzytaotao-manager\xzytaotao-manager-pojo\target\classes [INFO] [INFO] <<< tomcat7-maven-plugin:2.2:run (default-cli) @ xzytaotao-manager-pojo <<< [INFO] [INFO] --- tomcat7-maven-plugin:2.2:run (default-cli) @ xzytaotao-manager-pojo --- [INFO] Skipping non-war project [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building xzytaotao-manager-dao 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ xzytaotao-manager-dao --- [INFO] Deleting M:\Myeclipseworkspaces\xzytaotao-manager\xzytaotao-manager-dao\target [INFO] [INFO] >>> tomcat7-maven-plugin:2.2:run (default-cli) @ xzytaotao-manager-dao >>> [INFO] [INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ xzytaotao-manager-dao --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 11 resources [INFO] [INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ xzytaotao-manager-dao --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 11 source files to M:\Myeclipseworkspaces\xzytaotao-manager\xzytaotao-manager-dao\target\classes [INFO] [INFO] <<< tomcat7-maven-plugin:2.2:run (default-cli) @ xzytaotao-manager-dao <<< [INFO] [INFO] --- tomcat7-maven-plugin:2.2:run (default-cli) @ xzytaotao-manager-dao --- [INFO] Skipping non-war project [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building xzytaotao-manager-service 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ xzytaotao-manager-service --- [INFO] Deleting M:\Myeclipseworkspaces\xzytaotao-manager\xzytaotao-manager-service\target [INFO] [INFO] >>> tomcat7-maven-plugin:2.2:run (default-cli) @ xzytaotao-manager-service >>> [INFO] [INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ xzytaotao-manager-service --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 0 resource [INFO] [INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ xzytaotao-manager-service --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 14 source files to M:\Myeclipseworkspaces\xzytaotao-manager\xzytaotao-manager-service\target\classes [INFO] /M:/Myeclipseworkspaces/xzytaotao-manager/xzytaotao-manager-service/src/main/java/com/xzytaotao/service/impl/ItemParamItemServiceImpl.java: M:\Myeclipseworkspaces\xzytaotao-manager\xzytaotao-manager-service\src\main\java\com\xzytaotao\service\impl\ItemParamItemServiceImpl.java使用了未经检查或不安全的操作。 [INFO] /M:/Myeclipseworkspaces/xzytaotao-manager/xzytaotao-manager-service/src/main/java/com/xzytaotao/service/impl/ItemParamItemServiceImpl.java: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。 [INFO] [INFO] <<< tomcat7-maven-plugin:2.2:run (default-cli) @ xzytaotao-manager-service <<< [INFO] [INFO] --- tomcat7-maven-plugin:2.2:run (default-cli) @ xzytaotao-manager-service --- [INFO] Skipping non-war project [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building xzytaotao-manager-web 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ xzytaotao-manager-web --- [INFO] Deleting M:\Myeclipseworkspaces\xzytaotao-manager\xzytaotao-manager-web\target [INFO] [INFO] >>> tomcat7-maven-plugin:2.2:run (default-cli) @ xzytaotao-manager-web >>> [INFO] [INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ xzytaotao-manager-web --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 7 resources [INFO] [INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ xzytaotao-manager-web --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 8 source files to M:\Myeclipseworkspaces\xzytaotao-manager\xzytaotao-manager-web\target\classes [INFO] [INFO] <<< tomcat7-maven-plugin:2.2:run (default-cli) @ xzytaotao-manager-web <<< [INFO] [INFO] --- tomcat7-maven-plugin:2.2:run (default-cli) @ xzytaotao-manager-web --- [INFO] Running war on http://localhost:8080/ [INFO] Creating Tomcat server configuration at M:\Myeclipseworkspaces\xzytaotao-manager\xzytaotao-manager-web\target\tomcat [INFO] create webapp with contextPath: 六月 04, 2017 9:48:09 下午 org.apache.coyote.AbstractProtocol init 信息: Initializing ProtocolHandler ["http-bio-8080"] 六月 04, 2017 9:48:09 下午 org.apache.catalina.core.StandardService startInternal 信息: Starting service Tomcat 六月 04, 2017 9:48:09 下午 org.apache.catalina.core.StandardEngine startInternal 信息: Starting Servlet Engine: Apache Tomcat/7.0.47 六月 04, 2017 9:48:13 下午 org.apache.catalina.core.ApplicationContext log 信息: No Spring WebApplicationInitializer types detected on classpath 六月 04, 2017 9:48:13 下午 org.apache.catalina.core.ApplicationContext log 信息: 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. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. 运行我的聚合工程xzytaotao-manager. 命令:clean tomcat7:run,正常启动不报错,按照学习视频应该能访问http://localhost:8080然后访问index.jsp的但是却连不上,而且8080端口没有被占用,一直找不到运行,求大神指点一下小弟!
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页