使用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(回车即可打印出信息)
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(回车即可打印出信息)