Maven 添加自定義 archetype

環境:jdk7  maven3.23  eclipse marsapache

關於maven是使用插件自帶的仍是單獨下載的,應該都是能夠的,可是要注意maven和jdk版本的問題,好比3.2.3版本的maven支持jdk6,更高版本的maven就不支持jdk6了,這一點在maven官網release history裏面有說明。eclipse

 

另外官網也有建立新archetype的說明,可是弄了好久,不成功,最後參考了下面的博客才搞定maven

http://blog.csdn.net/wangwei_cq/article/details/7911730ui

1.新建一個maven項目,配好做爲一個模板項目你所須要的東西,好比配置文件,類文件。在這裏,官網說明要建立artifact爲archetype類型的項目,但實際上任何maven項目應該均可以。spa

2.在該項目的pom.xml中,在<build>下面添加<pluginManagement>內容,以下:.net

<build>
        <finalName>blog</finalName>
        <pluginManagement>  
            <plugins>  
                <plugin>  
                    <groupId>org.apache.maven.plugins</groupId>  
                    <artifactId>maven-archetype-plugin</artifactId>  
                    <version>2.2</version>  
                </plugin>  
                <plugin>  
                    <groupId>org.apache.maven.plugins</groupId>  
                    <artifactId>maven-compiler-plugin</artifactId>  
                    <configuration>  
                        <source>1.5</source>  
                        <target>1.5</target>  
                    </configuration>  
                </plugin>  
                <plugin>  
                    <groupId>org.apache.maven.plugins</groupId>  
                    <artifactId>maven-resources-plugin</artifactId>  
                    <configuration>  
                        <encoding>UTF-8</encoding>  
                    </configuration>  
                </plugin>  
            </plugins>  
        </pluginManagement>
    </build>

3.進入該項目的根目錄,運行:mvn archetype:create-from-project插件

該命令使用剛纔配好的插件,會在target目錄下面生成generated-sources目錄,這個就是生成的 archetypecode

4.進入generated-sourced/archetype目錄,運行maven命令:mvn install   (最好保存第三步生成的archetype,未來就能夠在新機器上使用該命令安裝該archetype)xml

5.新建maven項目,就能看到該archetype了,但須要注意,例如我這裏項目是snapshoot類型,須要在eclipse中查看archetpe的時候勾選顯示snapshoot類型才能看到。blog

相關文章
相關標籤/搜索