<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 如何使用 Maven 創建 Java WAR 文件 > 原文: [https://javatutorial.net/how-to-create-java-war-file-with-maven](https://javatutorial.net/how-to-create-java-war-file-with-maven) 在繼續進行下一步之前,請確保已在系統上安裝了 JDK 和 Maven。 ![java-featured-image](https://img.kancloud.cn/05/3e/053ee0bb59842d92359246c98f815e0c_780x330.jpg) 如果您尚未安裝 JDK,[請點擊此處](https://javatutorial.net/install-java-8-jdk-on-ubuntu)。 如果您尚未安裝 Maven,[請點擊此處](https://javatutorial.net/how-to-install-maven-on-windows-linux-and-mac)。 ## 使用 Eclipse 生成 WAR 文件 步驟 1 – 打開 Eclipse 并創建一個新的 Maven 項目(文件 -&gt; 新建 -&gt; 其他 -&gt; Maven 項目) ![How to generate WAR file using Maven java example](https://img.kancloud.cn/8b/1c/8b1c3e8a935dcea953ca734c434574e6_689x504.jpg) 步驟 2 – 創建 Maven 項目后,在新窗口中單擊“下一步”,如下所示: ![How to generate WAR file using Maven java example](https://img.kancloud.cn/c6/21/c621acecfa45682be8368b5b0192208c_719x646.jpg) 步驟 3 – 選擇`maven-archetype-webapp`并單擊“Next”,如下所示: ![How to generate WAR file using Maven java example](https://img.kancloud.cn/0b/53/0b530c7995e7d2cecca7edda32de913f_706x648.jpg) 步驟 4 – 輸入詳細信息,例如我的,然后單擊“完成” ![How to generate WAR file using Maven java example](https://img.kancloud.cn/95/67/956714dc4dfc1d30175ffb84f69ce1b5_705x646.jpg) 您的 Maven 項目目錄應類似于以下內容: ![How to generate WAR file using Maven java example](https://img.kancloud.cn/67/dc/67dc1dcb3991567665cc5baf54902d55_479x163.jpg) 并且`pom.xml`應該看起來像這樣: ```java <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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>createwar</groupId> <artifactId>createwar</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>createwar Maven Webapp</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> <build> <finalName>createwar</finalName> </build> </project> ``` 步驟 6 – 將`pom.xml`替換為以下代碼: ```java <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>CrunchifyTutorial</groupId> <artifactId>CrunchifyTutorial</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <build> <sourceDirectory>src</sourceDirectory> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> <plugin> <artifactId>maven-war-plugin</artifactId> <version>2.4</version> <configuration> <warSourceDirectory>WebContent</warSourceDirectory> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> </dependency> </dependencies> </project> ``` 最重要的幾行是: ```java <packaging>war</packaging> ``` 和: ```java <artifactId>maven-compiler-plugin</artifactId> ``` 這就是我們有效地將其轉換為 WAR 的地方。 步驟 7 – 右鍵點擊“Project- &gt; Run As -&gt; Maven build…” ![java maven install](https://img.kancloud.cn/ce/7a/ce7a15d1b9c692cb0c5a7c831d588224_965x742.jpg) 步驟 8 – 在“目標”部分中鍵入`clean install`,然后單擊“運行”,如下所示: ![maven clean install java](https://img.kancloud.cn/40/76/4076121bb6705868f91756a22385db9a_679x685.jpg) 步驟 9 – 您應該看到`BUILD SUCCESS`,像這樣: ![Java maven clean install build success](https://img.kancloud.cn/c3/ec/c3ec72d68653430660da5c5e5263a42f_1656x420.jpg) 恭喜! 您有您的`.war`文件。 ![java war file maven install](https://img.kancloud.cn/d9/e3/d9e3d1536ecf879298834b628e3d3483_772x130.jpg) ## 使用 CMD 生成 WAR 文件 步驟 1 – 通過在我們安裝了 Java 的地方添加編譯器來修改`pom.xml`文件。 **pom.xml** ```java <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>craetewar</groupId> <artifactId>craetewar</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <name>craetewar</name> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.2.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> <build> <finalName>createwarexample</finalName> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <fork>true</fork> <executable>C:\Program Files\Java\jdk1.8.0_211\bin\javac.exe</executable> </configuration> </plugin> </plugins> </build> </project> ``` **注意**:`<executable>`是重要的部分。 您的 Java 版本可能有所不同,請確保牢記這一點并放置正確的文件夾路徑。 步驟 2 – 在終端中轉到項目的文件夾路徑,例如: ![maven war file install cmd](https://img.kancloud.cn/47/04/4704217e6461a7859e2db74abed91f95_1104x87.jpg) 步驟 3 - 運行`mvn clean install`,它將負責創建 WAR 文件: ![java maven clean install command cmd eclipse](https://img.kancloud.cn/37/d2/37d2cacd8d06ae71a3f2f43e277f866f_1819x963.jpg) 有我們的 WAR 文件: ![Java maven install war file cmd eclipse clean install build](https://img.kancloud.cn/5d/c9/5dc9df30b8edf2e0d932382cfb18f42d_810x143.jpg) 好的! 我們已經成功使用 Eclipse 和 Terminal 生成了 WAR 文件。 如果您有興趣生成 JAR 文件,我已經有關于該主題的文章。 您可以通過[單擊此處](https://javatutorial.net/how-to-create-java-jar-file-with-maven)來遵循它。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看