創建一個Maven原型

通過優銳課的java架構學習分鐘中,整理了本教程,以瞭解如何從現有項目中創建Maven原型。 此人使用Eclipse IDE創建Maven項目

Java面試必備之JVM+GC教程
介紹

很多時候,我們需要創建一個Maven原型來分發項目模板。 在本文的本文中,我將描述從現有項目創建Maven原型是多麼容易。

創建一個Maven項目

首先,讓我們創建一個非常簡單的Maven項目。 我正在使用Eclipse IDE創建Maven項目。 這是項目的pom.xml文件:

<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>com.porua</groupId>
    <artifactId>archetype-porua</artifactId>
    <version>1.0.0</version>
    <dependencies>
        <dependency>
            <groupId>com.porua</groupId>
            <artifactId>porua-container</artifactId>
            <version>1.0.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>1.4.196</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <id>make-fat-jar</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <descriptorRefs>
                                <descriptorRef>jar-with-dependencies</descriptorRef>
                            </descriptorRefs>
                            <finalName>${project.artifactId}-${project.version}</finalName>
                            <appendAssemblyId>false</appendAssemblyId>
                        </configuration>
                    </execution>
                    <execution>
                        <id>zip-all</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <descriptors>
                                <descriptor>src/assembly/assembly.xml</descriptor>
                            </descriptors>
                            <finalName>${project.artifactId}-${project.version}</finalName>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <repositories>
        <repository>
            <id>porua-repo</id>
            <name>Porua Repository</name>
            <url>https://github.com/anupamgogoi0907/porua-docs/raw/repo</url>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
            </snapshots>
            <releases>
                <enabled>true</enabled>
            </releases>
        </repository>
    </repositories>
</project>

現在轉到項目的根目錄,並依次執行以下命令:

MVN原型:從項目創建

該命令將從現有的Maven項目中生成原型。 你可以在以下位置檢查生成的文件:
目標/生成源/原型
在這裏插入圖片描述
現在,你可以做兩件重要的事情:

修改target / generated-sources / archetype / pom.xml以在需要時添加其他內容

修改目標/生成源/原型/src/main/resources/META-INF/maven/archetype-metadata.xml以在原型中包含/排除文件等。 (請閱讀Maven的官方文檔以獲取更多信息)

mvn全新安裝

在target / generated-sources / archetype / pom.xml上執行此命令。 它將插件安裝在你的本地存儲庫中。

mvn原型:generate -DarchetypeCalalog = local

執行此命令以檢查本地存儲庫中可用的原型。

使用原型

至此,我們的原型已成功安裝在本地Maven存儲庫中。 讓我們嘗試利用它。 使用以下命令從原型創建項目:
mvn -B原型:生成
-DarchetypeGroupId = com.porua
-DarchetypeArtifactId = archetype-porua-archetype
-DgroupId = com.mycompany.app
-DartifactId =我的應用

結論
文章到這裏,從現有項目中創建Maven原型非常簡單。

喜歡這篇文章的可以點個贊,歡迎大家留言評論,記得關注我,每天持續更新技術乾貨、職場趣事、海量面試資料等等
如果你對java技術很感興趣也可以+ qq羣:907135806 交流學習,共同學習進步。
不要再用"沒有時間“來掩飾自己思想上的懶惰!趁年輕,使勁拼,給未來的自己一個交代

文章寫道這裏,歡迎完善交流。最後奉上近期整理出來的一套完整的java架構思維導圖,分享給大家對照知識點參考學習。有更多JVM、Mysql、Tomcat、Spring Boot、Spring Cloud、Zookeeper、Kafka、RabbitMQ、RockerMQ、Redis、ELK、Git等Java乾貨加vx:ddmsiqi 領取啦

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章