【IDEA】使用Maven骨架创建JavaWeb项目

IDEA版本:2020.1

骨架选项名称:

org.apache.maven.archetypes:maven-archetype-webapp

本项目的Maven坐标设置:

设置优先从本地获取骨架:

archetypeCatalog=internal

构建过程的控制台打印:

"C:\Program Files\Java\jdk1.8.0_251\bin\java.exe" -Dmaven.multiModuleProjectDirectory=C:\Users\User-Dai\AppData\Local\Temp\archetypetmp -Dmaven.home=D:\apache-maven-3.6.3 -Dclassworlds.conf=D:\apache-maven-3.6.3\bin\m2.conf "-Dmaven.ext.class.path=C:\Program Files\JetBrains\IntelliJ IDEA 2020.1\plugins\maven\lib\maven-event-listener.jar" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2020.1\lib\idea_rt.jar=64704:C:\Program Files\JetBrains\IntelliJ IDEA 2020.1\bin" -Dfile.encoding=UTF-8 -classpath D:\apache-maven-3.6.3\boot\plexus-classworlds-2.6.0.jar;D:\apache-maven-3.6.3\boot\plexus-classworlds.license org.codehaus.classworlds.Launcher -Didea.version2020.1 -s D:\apache-maven-3.6.3\conf\settings.xml -Dmaven.repo.local=D:\maven-storage -DinteractiveMode=false -DgroupId=cn.echo42 -DartifactId=Maven-Archetype-Sample -Dversion=1.0-SNAPSHOT -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-webapp -DarchetypeVersion=RELEASE -DarchetypeCatalog=internal org.apache.maven.plugins:maven-archetype-plugin:RELEASE:generate
[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO] 
[INFO] >>> maven-archetype-plugin:3.2.0:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO] 
[INFO] <<< maven-archetype-plugin:3.2.0:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO] 
[INFO] 
[INFO] --- maven-archetype-plugin:3.2.0:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Batch mode
[INFO] Archetype repository not defined. Using the one from [org.apache.maven.archetypes:maven-archetype-webapp:1.0] found in catalog internal
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: maven-archetype-webapp:RELEASE
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: cn.echo42
[INFO] Parameter: artifactId, Value: Maven-Archetype-Sample
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: package, Value: cn.echo42
[INFO] Parameter: packageInPathFormat, Value: cn/echo42
[INFO] Parameter: package, Value: cn.echo42
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: groupId, Value: cn.echo42
[INFO] Parameter: artifactId, Value: Maven-Archetype-Sample
[INFO] Project created from Archetype in dir: C:\Users\User-Dai\AppData\Local\Temp\archetypetmp\Maven-Archetype-Sample
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  4.503 s
[INFO] Finished at: 2020-08-04T20:57:23+08:00
[INFO] ------------------------------------------------------------------------

目录结构:

发现我们的源码包和资源包都没有配置,只有一个放置页面资源的webapp目录

我们可以把webapp拖动放到我们想存放的位置:

自己手动配置Resource和Java目录

在对main目录进行右键创建包的时候,IDEA会自动建议创建Maven项目的目录结构

JSP首页甚至没有JSP指令标签。。。

<html>
<body>
<h2>Hello World!</h2>
</body>
</html>

可以把POM配置这些都更新:

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.13</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

也就是说这个骨架最初并不是给IDEA创建的

而是给Eclipse使用的。。。

接下来是配置Tomcat

点加号找到TomcatServer选择本地,千万别下面的EE Server

IDEA会提示你还没有配置Tomcat,直接Fix就好了

选下面这个explored的

自行更换工程资源路径:

重要的热部署选上:

启动项目发现404,结果之前好好的webapp目录IDEA不识别了

因为默认的配置路径IDEA找不到了,需要我们自己改上去:

 

把之前的index.jsp删除,重新配置一个

<%--
  Created by IntelliJ IDEA.
  User: User-Dai
  Date: 2020/8/4
  Time: 21:18
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
    
    Hello Java
</body>
</html>

okokok

 

posted @ 2020-08-04 21:21  emdzz  阅读(1428)  评论(0编辑  收藏  举报