新建项目

生成对应的webapp目录:

生成的pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>neusoft</groupId>
<artifactId>mavenwebapp</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>mavenwebapp Maven Webapp</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>mavenwebapp</finalName>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
缺少 java 与resource文件夹,添加目录 到main下
然后点击 projectStructure 配置 sources 与 resources 标记到目录上

完成后目录图标如下

idea集成tomcat
点击add configuration 选择tomcat Server 在选择对应的服务器 这里我们要发布到本地服务器 选择local

点击configure 选择tomcat安装路径

点击ok 再点击apply完成配置

配置deployment 发布
artifacts:是maven中的一个概念,表示项目/modules如何打包,比如jar,war,war exploded,ear等打包形式,一个项目或者说module有了artifacts就可以部署到web应用服务器上了。然后进行发布访问。
先添加tomcat

配置成功

选择deployment选项卡 点击+ 添加项目 选择war exployed模式
(1)war模式这种可以称之为是发布模式,看名字也知道,这是先打成war包,再发布;
(2)war exploded模式是直接把文件夹、jsp页面 、classes等等移到Tomcat 部署文件夹里面,进行加载部署。因此这种方式支持热部署,一般在开发的时候也是用这种方式。
(3)在平时开发的时候,使用热部署的话,应该对Tomcat进行相应的设置,这样的话修改的jsp界面什么的东西才可以及时的显示出来。

若要实现热部署 重新回到server选项卡 改变更新时机


选择tomcat发布的目录


更改web路径此时返回server选项卡 发现url项发生改变 路径改为/mavenwebapp


此时tomcat部署完成 右上角出现tomcat 点击运行

运行时如果出现如下问题
CATALINA_HOME是Tomcat的安装目录,CATALINA_BASE是Tomcat的工作目录。而CATALINA_BASE到c盘去了我们可以 在环境变量 或者idea中进行配置 这里我在idea进行配置
Tomcat每个运行实例需要使用自己的conf、logs、temp、webapps、work和shared目录,因此CATALINA_BASE就 指向这些目录。

重新修改idea的tomcat配置

启动tomcat访问当前路径


网友评论