IDEA安装及创建Maven项目教程【史上最详细】(二)

简介: IDEA安装及创建Maven项目教程【史上最详细】(二)

三、IDEA创建Maven项目

在创建项目之前我们了解一个简单的概念。

在 IntelliJ IDEA 中,项目(Project)也是一个独立的实体,但它更加灵活和细粒度。在 IntelliJ IDEA 中,一个项目可以包含多个模块(Module),每个模块可以有自己的源代码和设置。这种模块化的方式使得在 IntelliJ IDEA 中更容易管理大型项目。此外,IntelliJ IDEA 还引入了概念称为 "工作区"(Workspace),它类似于 Eclipse 的工作空间,用于组织和管理多个项目。

例如:

idea project ==>eclipse workspce

idea  module==>eclipse project

1.配置Maven

1).设置编码集

2.输入File Encodings将编码改为UTF-8

3.配置maven安装路径

2.创建工作区

1). 配置JDK

2). 修改项目存放路径

这样我们的工作区间就创建好啦

3.创建module模块

1).在工作区间上右击➡Next➡Module

2).选择我们自己的JDK➡输入webapp后CTRL+↓选择maven-archetype-webapp➡Next

3).为module模块取名

4.配置Maven Property

小贴士:  

 archetypeCatalog用来指定maven-archetype-plugin读取archetype-catalog.xml文件的位置:

   internal——maven-archetype-plugin内置的

   local——本地的,位置为~/.m2/archetype-catalog.xml

   remote——指向Maven中央仓库的Catalog

5.pom.xml配置依赖以及Maven插件

依赖字符串:

<dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.44</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>4.0.1</version>
            <scope>provided</scope>
        </dependency>

Maven插件

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
   </plugin>

选择“手动挡”,不然你的代码有问题系统也会去下载依赖,本身代码就是错的下载也肯定失败,所以选择“手动挡”。

6.web.xml从2.3版本换成3.1

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"

        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

        xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"

        version="3.1">

7.编写Servlet和JSP页面测试

JSP页面

<%--
  Created by IntelliJ IDEA.
  User: 索隆
  Date: 2023/8/11
  Time: 17:52
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title></title>
</head>
<body>
helllo idea我是jsp页面
</body>
</html>

Servlet层

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
 * @author Java方文山
 * @compay csdn_Java方文山
 * @create 2023-08-11-17:46
 */
@WebServlet("/idea")
public class DemoServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("hello idea我是后端Servlet");
        req.getRequestDispatcher("/index.jsp").forward(req,resp);
    }
}

7.配置Tomcat服务器

8.更改网络访问地址

运行结果:

到这里我的分享就结束了,欢迎到评论区探讨交流!!

如果觉得有用的话还请点个赞吧 ♥  ♥

相关文章
|
3天前
|
Java Apache Maven
Maven 项目文档
在C:/MVN下,使用命令`mvn archetype:generate -DgroupId=com.companyname.bank -DartifactId=consumerBanking -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false`创建Maven Java项目。确保`pom.xml`包含`maven-site-plugin`和`maven-project-info-reports-plugin`配置,版本分别至少为3.3和2.7,以避免`NoClassDefFoundError`。
|
6天前
|
Java 应用服务中间件 Maven
Spring Boot项目打war包(idea:多种方式)
Spring Boot项目打war包(idea:多种方式)
20 1
|
4天前
|
Java Maven
SpringBoot项目的用maven插件打包报Test错误
SpringBoot项目的用maven插件打包报Test错误
|
6天前
|
Java Maven
Maven配置以及IDEA设置(Cannot resolve plugin org.apache.maven.plugins:报错)
Maven配置以及IDEA设置(Cannot resolve plugin org.apache.maven.plugins:报错)
27 1
|
6天前
|
Java Apache Maven
Maven 项目文档
在 `C:/MVN` 目录下创建 Maven 项目 `consumerBanking` 使用命令:`mvn archetype:generate -DgroupId=com.companyname.bank -DartifactId=consumerBanking -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false`。为解决 `mvn site` 命令执行时的 `NoClassDefFoundError`
|
2天前
|
Java Maven
Maven 构建 Java 项目
使用 Maven 的 archetype:generate 命令创建 Java 项目,如 `mvn archetype:generate` -DgroupId=com.companyname.bank -DartifactId=consumerBanking -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false,在 C:\MVN 下生成基于 maven 的 consumerBanking 项目。
|
3天前
|
前端开发 JavaScript Java
Maven实战 Item3 -- Maven项目构建2_构建一个maven2 3项目
Maven实战 Item3 -- Maven项目构建2_构建一个maven2 3项目
|
3天前
|
JavaScript 安全 前端开发
Maven实战 Item2 -- Maven项目构建(手动)_term2 配置maven(2)
Maven实战 Item2 -- Maven项目构建(手动)_term2 配置maven(2)
|
3天前
|
前端开发 Java Maven
Maven实战 Item2 -- Maven项目构建(手动)_term2 配置maven(1)
Maven实战 Item2 -- Maven项目构建(手动)_term2 配置maven(1)
|
6天前
|
存储 Java Maven
Maven 构建 Java 项目
使用 Maven 的 `maven-archetype-quickstart` 插件在 `C:\MVN` 创建 Java 应用项目 `consumerBanking`,命令行参数包括 `-DgroupId`, `-DartifactId` 和 `-DarchetypeArtifactId`。项目包含 src/main/java 和 src/test/java 目录,分别存放 Java 代码和测试代码,以及 src/main/resources 用于存储资源文件。默认生成的 `App.java` 和 `AppTest.java` 分别为应用主类和测试类。

热门文章

最新文章

推荐镜像

更多