mvn命令建立archetype項目骨架順序

使用Maven2創建典型的三類項目:

1. 普通的Java項目,如基礎包等:
    mvn archetype:create -DgroupId=com.company -DartifactId=project -DarchetypeArtifactId=maven-archetype-quickstart
 
2. 普通的Web項目,如一個Web項目:
    mvn archetype:create -DgroupId=com.company -DartifactId=project -DarchetypeArtifactId=maven-archetype-webapp

3. Appfuse中的Struts 2.0項目:
    mvn archetype:create -DarchetypeGroupId=org.appfuse -DarchetypeArtifactId=appfuse-basic-struts -DremoteRepositories=http://static.appfuse.org/repository -DarchetypeVersion=2.0-m4-SNAPSHOT -DgroupId=com.mycompany -DartifactId=myproject

使用上述命令後,可以很快捷地生成你想要的項目原型。

『第一方案』
接下來只需使用下面命令,生成IDEA的項目文件,然後打開就可以在IDEA下進行項目開發了。
     mvn idea:idea -DdownloadSources=true -DdownloadJavadocs=true -DjdkLevel=1.7
當pom.xml文件發生變化時,只需使用下面命令重新生成module文件即可,新生成的module文件會和原來module文件進行很好的合併,通常是依賴的package發生變化了.
    mvn idea:module
 『第二方案』
在IDEA中打開maven工程, 就可以在IDEA下進行項目開發了。
當pom.xml文件發生變化時,只需使用 Maven project  ReImport 動作就可以。

----------------------------------------------
1、先制定一個空間如:在D:\IDEAspace中,打開CMD回車後,d:(回車後),cd D:\IDEAspace(回車即可進入IDEAspace盤符中)

2、執行mvn archetype:generate

3、提示選擇,直接按回車默認選擇:maven-archetype-quickstart
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 521:(直接回車)

4、之後提示選擇maven-archetype-quickstart的版本
Choose org.apache.maven.archetypes:maven-archetype-quickstart version:
1: 1.0-alpha-1
2: 1.0-alpha-2
3: 1.0-alpha-3
4: 1.0-alpha-4
5: 1.0
6: 1.1
Choose a number: 6:// 4、直接按回車默認選擇第6項

5、接着提示輸入groupId、artifactId、 version、以及包名package,如下
Define value for property 'groupId': : com.liu
Define value for property 'artifactId': : helloworld
Define value for property 'version':  1.0-SNAPSHOT: :1.0-SNAPSHOT
Define value for property 'package':  com.liu: : com.liu.helloworld
Confirm properties configuration:
groupId: com.liu
artifactId: helloworld
version: 1.0-SNAPSHOT
package: com.liu.helloworld
 Y: : Y // 6、回車,進行最後確認


6、// 進行工程目錄
cd helloworld
//構建成功後,再進行編譯打包
// 編譯打包前需要修改pom.xml文件,在</dependencies>標籤後增加
<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-shade-plugin</artifactId>
      <version>1.2.1</version>
      <configuration>
        <transformers>
          <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
            <manifestEntries>
              <Main-Class>com.liu.helloworld.App</Main-Class>
            </manifestEntries>
          </transformer>
        </transformers>
      </configuration>
      <executions>
        <execution>
          <phase>package</phase>
          <goals>
            <goal>shade</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

// 參考:http://maven.apache.org/plugins/maven-shade-plugin/usage.html

// 打包
mvn clean package

//運行打包文件
java -jar target\helloworld-1.0-SNAPSHOT.jar(回車即可打印出信息)

發佈了3 篇原創文章 · 獲贊 2 · 訪問量 10萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章