美文网首页
IDEA 建立Maven骨架的Web项目

IDEA 建立Maven骨架的Web项目

作者: JohnYuCN | 来源:发表于2020-02-01 18:54 被阅读0次

一、IDEA 的WEB开发环境设置:

Preferences->Build,Execution,Deployment->ApplicaionServers->“点击+”添加Java应用服务器

二、新建项目Maven项目:

  1. File->New->Project...->选择Maven
  2. 不选择“Create From Archetyp”(或者选择Maven-archetype-webapp)->Next
  3. 填写GroupId和ArtifactId->Next->Finish

三、调整项目的配置

  1. 在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>cn.johnyu</groupId>
    <artifactId>temp1</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>
    <dependencies>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>4.0.1</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <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>
                    <showWarnings>true</showWarnings>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
  1. 在项目的src->main下新建文件夹及web.xml
  • 目录结构:
main
├── java
│   └── cn
│       └── johnyu
├── resources
└── webapp
    ├── WEB-INF
    │   └── web.xml
    └── index.jsp

  • web.xml
<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_4_0.xsd"
         version="4.0">

</web-app>
  • 查看Facets:
    在项目上点右键->Open Modules Setttings->选择Facets,此时可以看到“Web”的相关配置。

四、运行设置:

  1. Run菜单->Edit Configurations...->点击“+”选择Tomca tServer->选择Local->此时出现
    对话框。
  2. 选择Deployemnt选项卡->点击"+"选择Artifact->选择"temp1: war exploded"(代表热更新)
  3. 在Server选项卡中适当更新,如图:


    注意:URL,Update,frame的配置
  1. 运行:temp1-web-run。


    运行

相关文章

网友评论

      本文标题:IDEA 建立Maven骨架的Web项目

      本文链接:https://www.haomeiwen.com/subject/prhxxhtx.html