zoukankan      html  css  js  c++  java
  • IDEA使用Maven搭建JavaWeb项目

    1. 新建项目

    2. 填写项目坐标信息

    3. 手动生效pom.xml

    4. 添加maven常用配置

    1) 设置项目统一编码

    1 <!-- 设置编码 -->
    2 <properties>
    3     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    4 </properties>

    2) 配置基本插件

     1 <!-- 设置编译器版本 JDK1.8 -->
     2 <plugin>
     3     <groupId>org.apache.maven.plugins</groupId>
     4     <artifactId>maven-compiler-plugin</artifactId>
     5     <version>3.3</version>
     6     <configuration>
     7         <source>1.8</source>
     8         <target>1.8</target>
     9     </configuration>
    10 </plugin>
    11 
    12 <!-- 跳过Maven打包时的单元测试 可选
    13 <plugin>
    14     <groupId>org.apache.maven.plugins</groupId>
    15     <artifactId>maven-surefire-plugin</artifactId>
    16     <version>2.18.1</version>
    17     <configuration>
    18         <skipTests>true</skipTests>
    19     </configuration>
    20 </plugin> -->

    5. 转为JavaWeb项目

    8. 设置打包方式为war

    1 <!-- 设置打包方式 -->
    2 <packaging>war</packaging>

    7. 添加JavaWeb依赖

     1 <!-- 依赖 -->
     2 <dependencies>
     3     <!-- Servlet -->
     4     <dependency>
     5         <groupId>javax.servlet</groupId>
     6         <artifactId>javax.servlet-api</artifactId>
     7         <version>3.1.0</version>
     8         <scope>provided</scope>
     9     </dependency>
    10     <!-- JSP -->
    11     <dependency>
    12         <groupId>javax.servlet</groupId>
    13         <artifactId>jsp-api</artifactId>
    14         <version>2.0</version>
    15         <exclusions>
    16             <exclusion>
    17                 <artifactId>servlet-api</artifactId>
    18                 <groupId>javax.servlet</groupId>
    19             </exclusion>
    20         </exclusions>
    21     </dependency>
    22     <!-- JSTL -->
    23     <dependency>
    24         <groupId>jstl</groupId>
    25         <artifactId>jstl</artifactId>
    26         <version>1.2</version>
    27         <scope>runtime</scope>
    28     </dependency>
    29 </dependencies>

    8. 准备测试的JSP和Servlet

    9. 配置tomcat服务器

    设置常规参数

    部署web项目

    配置虚拟目录

    10. 添加tomcat7启动插件

    1 <!-- tomcat7启动插件 -->
    2 <plugin>
    3     <groupId>org.apache.maven.plugins</groupId>
    4     <artifactId>tomcat7-maven-plugin</artifactId>
    5     <version>2.2</version>
    6     <configuration>
    7         <path>/${project.artifactId}</path>
    8     </configuration>
    9 </plugin>

    11. 使用tomcat插件启动web项目

    12. 访问网站

    附: 完整pom.xml

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <project xmlns="http://maven.apache.org/POM/4.0.0"
     3          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     4          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     5     <modelVersion>4.0.0</modelVersion>
     6 
     7     <groupId>cn.burgundyred</groupId>
     8     <artifactId>chapter1</artifactId>
     9     <version>1.0-SNAPSHOT</version>
    10 
    11     <!-- 设置打包方式 -->
    12     <packaging>war</packaging>
    13 
    14     <!-- 设置编码 -->
    15     <properties>
    16         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    17     </properties>
    18 
    19     <!-- 依赖 -->
    20     <dependencies>
    21         <!-- Servlet -->
    22         <dependency>
    23             <groupId>javax.servlet</groupId>
    24             <artifactId>javax.servlet-api</artifactId>
    25             <version>3.1.0</version>
    26             <scope>provided</scope>
    27         </dependency>
    28         <!-- JSP -->
    29         <dependency>
    30             <groupId>javax.servlet</groupId>
    31             <artifactId>jsp-api</artifactId>
    32             <version>2.0</version>
    33             <scope>provided</scope>
    34             <exclusions>
    35                 <exclusion>
    36                     <artifactId>servlet-api</artifactId>
    37                     <groupId>javax.servlet</groupId>
    38                 </exclusion>
    39             </exclusions>
    40         </dependency>
    41         <!-- JSTL -->
    42         <dependency>
    43             <groupId>jstl</groupId>
    44             <artifactId>jstl</artifactId>
    45             <version>1.2</version>
    46             <scope>runtime</scope>
    47         </dependency>
    48     </dependencies>
    49 
    50     <!-- 插件 -->
    51     <build>
    52         <plugins>
    53             <!-- 设置编译器版本 JDK1.7 -->
    54             <plugin>
    55                 <groupId>org.apache.maven.plugins</groupId>
    56                 <artifactId>maven-compiler-plugin</artifactId>
    57                 <version>3.3</version>
    58                 <configuration>
    59                     <source>1.7</source>
    60                     <target>1.7</target>
    61                 </configuration>
    62             </plugin>
    63             <!-- 跳过Maven打包时的单元测试 可选
    64             <plugin>
    65                 <groupId>org.apache.maven.plugins</groupId>
    66                 <artifactId>maven-surefire-plugin</artifactId>
    67                 <version>2.18.1</version>
    68                 <configuration>
    69                     <skipTests>true</skipTests>
    70                 </configuration>
    71             </plugin> -->
    72             <!-- tomcat7启动插件 -->
    73             <plugin>
    74                 <groupId>org.apache.tomcat.maven</groupId>
    75                 <artifactId>tomcat7-maven-plugin</artifactId>
    76                 <version>2.2</version>
    77                 <configuration>
    78                     <path>/${project.artifactId}</path>
    79                 </configuration>
    80             </plugin>
    81         </plugins>
    82     </build>
    83 
    84 </project>
    View Code
  • 相关阅读:
    OpenJDK源码研究笔记(十二):JDBC中的元数据,数据库元数据(DatabaseMetaData),参数元数据(ParameterMetaData),结果集元数据(ResultSetMetaDa
    Java实现 LeetCode 257 二叉树的所有路径
    Java实现 LeetCode 257 二叉树的所有路径
    Java实现 LeetCode 257 二叉树的所有路径
    Java实现 LeetCode 242 有效的字母异位词
    Java实现 LeetCode 242 有效的字母异位词
    Java实现 LeetCode 242 有效的字母异位词
    Java实现 LeetCode 241 为运算表达式设计优先级
    Java实现 LeetCode 241 为运算表达式设计优先级
    Java实现 LeetCode 241 为运算表达式设计优先级
  • 原文地址:https://www.cnblogs.com/shaohsiung/p/9541136.html
Copyright © 2011-2022 走看看