<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>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # 如何使用 Maven 配置文件 > 原文: [https://javatutorial.net/how-to-use-maven-profiles](https://javatutorial.net/how-to-use-maven-profiles) 簡而言之, [Maven](https://javatutorial.net/how-to-install-maven-on-windows-linux-and-mac) 配置文件是一組覆蓋默認值的配置值。 通過使用它,您可以為不同的環境(生產/開發)創建自定義版本。 ![java-featured-image](https://img.kancloud.cn/05/3e/053ee0bb59842d92359246c98f815e0c_780x330.jpg) 在繼續學習本教程的內容之前,假定您已經安裝了 Maven。 如果您不這樣做,請按照本教程 的逐步指南進行操作。 要在 Maven 中指定配置文件,您需要使用`pom.xml`文件中的`activeProfiles`或配置文件元素。`pom.xml`在**運行時**時被修改。 有 3 種構建配置文件類型。 1. 每個項目 1. 在`pom.xml`文件中定義 2. 每位使用者 1. 在 Maven 設置 xml 文件(`%USER_HOME%/.m2/settings.xml`)中定義 3. 全球 1. 在 Maven 全局設置 xml 文件(`%M2_HOME%/conf/settings.xml`)中定義 如何提示 Maven Build 配置文件? 有兩種方法: 1. 終端–本教程涵蓋 2. Maven 設置–本教程涵蓋 3. 環境變量–在本教程中涵蓋 4. 操作系統設置 5. 存在或缺少文件 ### 顯式激活配置文件 創建您的 Maven 項目(如果尚未創建),然后創建第一個簡單的配置文件`test1`。 這是我添加的`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>mavenprofilesdemo</groupId> <artifactId>mavenprofilesdemo</artifactId> <packaging>jar</packaging> <version>0.0.1-SNAPSHOT</version> <name>Maven Quick Start Archetype</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> <profiles> <profile> <id>test1</id> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <fork>true</fork> <compilerVersion>1.5</compilerVersion> </configuration> </plugin> </plugins> </build> </profile> </profiles> </project> ``` `<profiles>` -&gt; `<profile>` -&gt; `id`;那是我們指定如何引用配置文件的地方。 不要錯過該行,這很重要,因為它不僅是必填項,而且如果您省略它,則將無法訪問您的個人資料。 我們在`pom.xml`文件中所做的是,我們已覆蓋了編譯器插件設置。 我們已將編譯器的版本設置為 1.5,并將`fork`設置為`true`。 請記住,在這種情況下,我們僅創建了 1 個配置文件,但是我們也可以在`<profiles>`標簽內添加更多`<profile>`標簽。 覆蓋所需的插件之后,該運行我們的配置文件了。 您可以通過在命令行中輸入`mvn test -P <id>`來運行它 在我們的例子中,我們需要編寫`mvn test -Ptest1`,因為我們創建的個人資料給我們提供了值為`test1`的 ID。 現在轉到項目的文件夾位置,然后輸入`mvn test -P <您的配置文件 ID>`。如果我在上面的示例中運行此命令,則得到的結果是: ```java [INFO]?Scanning?for?projects... [INFO] [INFO] ----------------< mavenprofilesdemo:mavenprofilesdemo >----------------- [INFO] Building Maven Quick Start Archetype 0.0.1-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ mavenprofilesdemo --- [WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory D:\Eclipse Projects\mavenprofilesdemo\src\main\resources [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ mavenprofilesdemo --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ mavenprofilesdemo --- [WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory D:\Eclipse Projects\mavenprofilesdemo\src\test\resources [INFO] [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ mavenprofilesdemo --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ mavenprofilesdemo --- [INFO] Surefire report directory: D:\Eclipse Projects\mavenprofilesdemo\target\surefire-reports ------------------------------------------------------- T E S T S ------------------------------------------------------- Running mavenprofilesdemo.mavenprofilesdemo.AppTest Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec Results : Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.072 s [INFO] Finished at: 2019-08-18T09:15:55+01:00 [INFO] ------------------------------------------------------------------------ ``` ### 使用 Maven 設置激活配置文件 轉到您的用戶主目錄,然后打開`.m2`文件夾。 如果那里沒有`settings.xml`文件,請創建一個。 然后將我們創建的配置文件添加為活動配置文件。 使用以下代碼: ```java <settings 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/settings-1.0.0.xsd"> <mirrors> <mirror> <id>maven.dev.snaponglobal.com</id> <name>Internal Artifactory Maven repository</name> <url>http://repo1.maven.org/maven2/</url> <mirrorOf>*</mirrorOf> </mirror> </mirrors> <activeProfiles> <activeProfile>test</activeProfile> </activeProfiles> </settings> ``` 現在,轉到包含`pom.xml`文件的文件夾并執行`mvn test`。 ### 使用環境變量激活配置文件 刪除`settings.xml`文件并在`name`標簽中添加`env`值。 像這樣: ```java <profile> <id>test</id> <activation> <property> <name>env</name> <value>test1</value> </property> </activation> </profile> ``` 您必須創建一個稱為`env`的環境變量,并將其值設置為`test1`。 轉到包含`pom.xml`的文件夾,然后鍵入`mvn test`。 如果您希望將自定義庫包含到 maven 本地存儲庫中,可以遵循[本文](https://javatutorial.net/how-to-include-custom-library-into-maven-local-repository)。
                  <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>

                              哎呀哎呀视频在线观看