激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - IDEA+Maven搭建JavaWeb項目的方法步驟

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

2022-03-08 13:57knightzz98 Java教程

本文主要介紹了IDEA+Maven搭建JavaWeb項目的方法步驟,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

 

前言

本章節主要內容是描述如何使用maven構建javaweb項目

Maven依賴倉庫:

https://mvnrepository.com/

Tomcat7插件的命令:

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

 

1. 項目搭建

選擇maven模板的 maven-app 模板創建項目 , 如下圖所示

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

設置maven相關配置

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

確認自己的maven配置目錄, 如果沒有設置, 默認會使用.m2的maven配置

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

 

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>

設置單元測試的版本

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

刪除pluginManagement標簽

<!-- 將這個標簽及標簽中的內容全部刪除 -->
<pluginManagement>
...
</pluginManagement>

 

添加web部署的插件

? 在 build 標簽中添加 plugins 標簽

Jetty插件

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

Tomcat插件

<!-- 設置在plugins標簽中 -->
<plugin>
	<groupId>org.apache.tomcat.maven</groupId>
	<artifactId>tomcat7-maven-plugin</artifactId>
	<version>2.1</version>
	<configuration>
		<port>8081</port> <!-- 啟動端口 默認:8080 -->
		<path>/test</path> <!-- 項目的站點名,即對外訪問路徑 -->
		<uriEncoding>UTF-8</uriEncoding> <!-- 字符集編碼 默認:ISO-8859-1 -->
		<server>tomcat7</server> <!-- 服務器名稱 -->
	</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>
      <!-- 設置在plugins標簽中 -->
      <plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>maven-jetty-plugin</artifactId>
        <version>6.1.25</version>
        <configuration>
          <!-- 熱部署,每10秒掃描一次 -->
          <scanIntervalSeconds>10</scanIntervalSeconds>
          <!-- 可指定當前項目的站點名 -->
          <contextPath>/test</contextPath>
          <connectors>
            <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
              <port>9090</port> <!-- 設置啟動的端口號 -->
            </connector>
          </connectors>
        </configuration>
      </plugin>

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

 

3. 項目運行

使用Jetty運行項目

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

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

也可以指定端口運行

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

使用jetty運行項目

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

在瀏覽器中顯示

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

啟動成功

[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插件

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

運行項目

[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:CodeWorkSpaceCodeAppspring-lesson-cloudspring-aoplesson-04-webapp arget omcat
[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"]

瀏覽器訪問

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

 

4. 注意事項

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

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

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

到此這篇關于IDEA+Maven搭建JavaWeb項目的文章就介紹到這了,更多相關IDEA + Maven 搭建JavaWeb項目內容請搜索服務器之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持服務器之家!

原文鏈接:https://blog.csdn.net/weixin_40040107/article/details/121054206

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 超碰人人做人人爱 | 中文字幕一区在线观看视频 | 欧美一级毛片大片免费播放 | 欧美日韩亚洲在线 | 亚州综合 | 国产精品一区在线免费观看 | 国产成人精品一区二区视频免费 | 龙床上的呻吟高h | 91精品国产91久久久久久 | www.91sese | 国产精品99久久久久久大便 | 成人在线观看免费观看 | 欧美高清在线精品一区二区不卡 | www.91成人 | 91视频观看 | 欧美一级黄色免费 | 动漫孕妇被羞羞视频 | 黄色美女免费 | 91麻豆精品国产91久久久更新资源速度超快 | 日本不卡中文字幕 | 一级毛片免费高清 | 国产精品久久久久久久久久久久久久久 | 久久久久97国产精 | 国产亚洲精品综合一区91555 | 久久久久久久久久久综合 | 久夜草| 成人不卡在线观看 | 亚洲一区二区中文字幕在线观看 | 免费观看一区二区三区视频 | 92自拍视频 | v11av在线播放 | 18被视频免费观看视频 | 亚州精品天堂中文字幕 | 成人三级电影在线 | 国产精品久久久久久影院8一贰佰 | 亚洲影视综合网 | 久久精品亚洲欧美日韩精品中文字幕 | 爽毛片| 国产资源在线视频 | 午夜精品成人一区二区 | 亚洲国产色婷婷 |