欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

IDEA+Maven搭建JavaWeb項目的方法步驟

 更新時間:2021年11月02日 08:34:41   作者:knightzz98  
本文主要介紹了IDEA+Maven搭建JavaWeb項目的方法步驟,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

前言

本章節(jié)主要內(nèi)容是描述如何使用maven構(gòu)建javaweb項目

Maven依賴倉庫:

https://mvnrepository.com/

Tomcat7插件的命令:

https://tomcat.apache.org/maven-plugin-trunk/tomcat7-maven-plugin/plugin-info.html

1. 項目搭建

選擇maven模板的 maven-app 模板創(chuàng)建項目 , 如下圖所示

在這里插入圖片描述

設(shè)置maven相關(guān)配置

在這里插入圖片描述

確認(rèn)自己的maven配置目錄, 如果沒有設(shè)置, 默認(rèn)會使用.m2的maven配置

在這里插入圖片描述

2. 配置項目

修改 JDK 的版本

<!-- JDN的版本修改為1.8 -->
<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>

設(shè)置單元測試的版本

<!-- junit的版本修改為4.12 -->
<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
</dependencies>

刪除pluginManagement標(biāo)簽

<!-- 將這個標(biāo)簽及標(biāo)簽中的內(nèi)容全部刪除 -->
<pluginManagement>
...
</pluginManagement>

添加web部署的插件

​ 在 build 標(biāo)簽中添加 plugins 標(biāo)簽

Jetty插件

<!-- 設(shè)置在plugins標(biāo)簽中 -->
<plugin>
   <groupId>org.mortbay.jetty</groupId>
   <artifactId>maven-jetty-plugin</artifactId>
   <version>6.1.25</version>
   <configuration>
      <!-- 熱部署,每10秒掃描一次 -->
      <scanIntervalSeconds>10</scanIntervalSeconds>
      <!-- 可指定當(dāng)前項目的站點名 -->
      <contextPath>/test</contextPath>                 
      <connectors>
          <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
              <port>9090</port> <!-- 設(shè)置啟動的端口號 -->
          </connector>
      </connectors>
   </configuration>
</plugin>  

Tomcat插件

<!-- 設(shè)置在plugins標(biāo)簽中 -->
<plugin>
	<groupId>org.apache.tomcat.maven</groupId>
	<artifactId>tomcat7-maven-plugin</artifactId>
	<version>2.1</version>
	<configuration>
		<port>8081</port> <!-- 啟動端口 默認(rèn):8080 -->
		<path>/test</path> <!-- 項目的站點名,即對外訪問路徑 -->
		<uriEncoding>UTF-8</uriEncoding> <!-- 字符集編碼 默認(rèn):ISO-8859-1 -->
		<server>tomcat7</server> <!-- 服務(wù)器名稱 -->
	</configuration>
</plugin>

完整POM文件參考

<?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.knightzz</groupId>
  <artifactId>lesson-04-webapp</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>lesson-04-webapp 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.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>

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

  <build>
    <finalName>lesson-04-webapp</finalName>

    <plugins>
      <!-- 設(shè)置在plugins標(biāo)簽中 -->
      <plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>maven-jetty-plugin</artifactId>
        <version>6.1.25</version>
        <configuration>
          <!-- 熱部署,每10秒掃描一次 -->
          <scanIntervalSeconds>10</scanIntervalSeconds>
          <!-- 可指定當(dāng)前項目的站點名 -->
          <contextPath>/test</contextPath>
          <connectors>
            <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
              <port>9090</port> <!-- 設(shè)置啟動的端口號 -->
            </connector>
          </connectors>
        </configuration>
      </plugin>

      <!-- 設(shè)置在plugins標(biāo)簽中 -->
      <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.1</version>
        <configuration>
          <port>8081</port> <!-- 啟動端口 默認(rèn):8080 -->
          <path>/lesson-04-webapp</path> <!-- 項目的站點名,即對外訪問路徑 -->
          <uriEncoding>UTF-8</uriEncoding> <!-- 字符集編碼 默認(rèn):ISO-8859-1 -->
          <server>tomcat7</server> <!-- 服務(wù)器名稱 -->
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

3. 項目運行

使用Jetty運行項目

點擊右上角的 "Add Configurations ",打開 “Run/Debug Configurations” 窗口, 添加相關(guān)配置

在這里插入圖片描述

也可以指定端口運行

jetty:run -Djetty.port=9090  # 需要將插件配置中的port標(biāo)簽去掉

使用jetty運行項目

在這里插入圖片描述

在瀏覽器中顯示

在這里插入圖片描述

啟動成功

[INFO] Starting jetty 6.1.25 ...
[INFO] jetty-6.1.25
[INFO] No Transaction manager found - if your webapp requires one, please configure one.
[INFO] Started SelectChannelConnector@0.0.0.0:9090
[INFO] Started Jetty Server
[INFO] Starting scanner at interval of 10 seconds.

使用Tomact插件運行項目

配置tomact插件

在這里插入圖片描述

運行項目

[INFO] --- tomcat7-maven-plugin:2.1:run (default-cli) @ lesson-04-webapp ---
[INFO] Running war on http://localhost:8081/lesson-04-webapp
[INFO] Creating Tomcat server configuration at K:\CodeWorkSpace\CodeApp\spring-lesson-cloud\spring-aop\lesson-04-webapp\target\tomcat
[INFO] create webapp with contextPath: /lesson-04-webapp
十月 31, 2021 3:10:03 下午 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["http-bio-8081"]
十月 31, 2021 3:10:03 下午 org.apache.catalina.core.StandardService startInternal
信息: Starting service Tomcat
十月 31, 2021 3:10:03 下午 org.apache.catalina.core.StandardEngine startInternal
信息: Starting Servlet Engine: Apache Tomcat/7.0.37
十月 31, 2021 3:10:04 下午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["http-bio-8081"]

瀏覽器訪問

在這里插入圖片描述

4. 注意事項

jetty 和 tomact 的插件配置都在pom文件里配置

 <plugins>
      <!-- 設(shè)置在plugins標(biāo)簽中 -->
      <plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>maven-jetty-plugin</artifactId>
        <version>6.1.25</version>
        <configuration>
          <!-- 熱部署,每10秒掃描一次 -->
          <scanIntervalSeconds>10</scanIntervalSeconds>
          <!-- 可指定當(dāng)前項目的站點名 -->
          <contextPath>/test</contextPath>
          <connectors>
            <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
              <port>9090</port> <!-- 設(shè)置啟動的端口號 -->
            </connector>
          </connectors>
        </configuration>
      </plugin>

      <!-- 設(shè)置在plugins標(biāo)簽中 -->
      <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.1</version>
        <configuration>
          <port>8081</port> <!-- 啟動端口 默認(rèn):8080 -->
          <path>/lesson-04-webapp</path> <!-- 項目的站點名,即對外訪問路徑 -->
          <uriEncoding>UTF-8</uriEncoding> <!-- 字符集編碼 默認(rèn):ISO-8859-1 -->
          <server>tomcat7</server> <!-- 服務(wù)器名稱 -->
        </configuration>
      </plugin>
    </plugins>

到此這篇關(guān)于IDEA+Maven搭建JavaWeb項目的文章就介紹到這了,更多相關(guān)IDEA + Maven 搭建JavaWeb項目內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • java編程FinalReference與Finalizer原理示例詳解

    java編程FinalReference與Finalizer原理示例詳解

    這篇文章主要為大家介紹了java編程FinalReference與Finalizer的核心原理以及示例源碼的分析詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助
    2022-01-01
  • 解決springboot集成swagger碰到的坑(報404)

    解決springboot集成swagger碰到的坑(報404)

    這篇文章主要介紹了解決springboot集成swagger碰到的坑(報404),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-06-06
  • stream中使用peek一些陷阱避免及解決方法

    stream中使用peek一些陷阱避免及解決方法

    這篇文章主要為大家介紹了stream中使用peek一些陷阱避免及解決方法詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-03-03
  • java實現(xiàn)爬取知乎用戶基本信息

    java實現(xiàn)爬取知乎用戶基本信息

    這篇文章主要為大家介紹了一個基于JAVA的知乎爬蟲,抓取知乎用戶基本信息,感興趣的小伙伴們可以參考一下
    2016-05-05
  • Spring基于ProxyFactoryBean創(chuàng)建AOP代理

    Spring基于ProxyFactoryBean創(chuàng)建AOP代理

    這篇文章主要介紹了Spring基于ProxyFactoryBean創(chuàng)建AOP代理,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2019-10-10
  • 一篇文章帶你玩轉(zhuǎn)JAVA單鏈表

    一篇文章帶你玩轉(zhuǎn)JAVA單鏈表

    這篇文章主要為大家詳細介紹了Java實現(xiàn)帶頭結(jié)點的單鏈表,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • SpringBoot+MyBatisPlus+Vue 前后端分離項目快速搭建過程(后端)

    SpringBoot+MyBatisPlus+Vue 前后端分離項目快速搭建過程(后端)

    這篇文章主要介紹了SpringBoot+MyBatisPlus+Vue 前后端分離項目快速搭建過程(后端),快速生成后端代碼、封裝結(jié)果集、增刪改查、模糊查找,畢設(shè)基礎(chǔ)框架,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-05-05
  • Java如何實現(xiàn)數(shù)字逆序

    Java如何實現(xiàn)數(shù)字逆序

    這篇文章主要介紹了Java如何實現(xiàn)數(shù)字逆序問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-04-04
  • SpringBoot整合騰訊云COS對象存儲實現(xiàn)文件上傳的示例代碼

    SpringBoot整合騰訊云COS對象存儲實現(xiàn)文件上傳的示例代碼

    本文主要介紹了SpringBoot整合騰訊云COS對象存儲實現(xiàn)文件上傳的示例代碼,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-12-12
  • 關(guān)于Tomcat出現(xiàn)The origin server did not find a current representation for the target resourc...的問題

    關(guān)于Tomcat出現(xiàn)The origin server did not find a current represent

    這篇文章主要介紹了關(guān)于Tomcat出現(xiàn)The origin server did not find a current representation for the target resourc...的問題,感興趣的小伙伴們可以參考一下
    2020-08-08

最新評論