maven创建web项目的命令
- mvn archetype:generate -DgroupId={packaging.path} -DartifactId={project-id}
-
-DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
P.S 替换 “{packaging.path}” 和“{project-id}” 的值为你想要的值
以下是一个具体的实例
1. mvn archetype:generate
首先在命令行下切换到你想要创建项目的目录,执行以下命令:
- N:\>cd workshop
-
-
N:\workshop> mvn archetype:generate -DgroupId=net.cublog.jersey -DartifactId=helloworldjersey -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
你会看到如下输出:
- N:\workshop> mvn archetype:generate -DgroupId=net.cublog.jersey -DartifactId=hel
-
loworldjersey -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=fa
-
lse
-
[INFO] Scanning for projects...
-
[INFO]
-
[INFO] ------------------------------------------------------------------------
-
[INFO] Building Maven Stub Project (No POM) 1
-
[INFO] ------------------------------------------------------------------------
-
[INFO]
-
[INFO] >>> maven-archetype-plugin:2.1:generate (default-cli) @ standalone-pom >>
-
>
-
[INFO]
-
[INFO] <<< maven-archetype-plugin:2.1:generate (default-cli) @ standalone-pom <<
-
<
-
[INFO]
-
[INFO] --- maven-archetype-plugin:2.1:generate (default-cli) @ standalone-pom --
-
-
-
[INFO] Generating project in Batch mode
-
[INFO] -------------------------------------------------------------------------
-
---
-
[INFO] Using following parameters for creating project from Old (1.x) Archetype:
-
maven-archetype-webapp:1.0
-
[INFO] -------------------------------------------------------------------------
-
---
-
[INFO] Parameter: groupId, Value: net.cublog.jersey
-
[INFO] Parameter: packageName, Value: net.cublog.jersey
-
[INFO] Parameter: package, Value: net.cublog.jersey
-
[INFO] Parameter: artifactId, Value: helloworldjersey
-
[INFO] Parameter: basedir, Value: N:\workshop
-
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
-
[INFO] project created from Old (1.x) Archetype in dir: N:\workshop\helloworldje
-
rsey
-
[INFO] ------------------------------------------------------------------------
-
[INFO] BUILD SUCCESS
-
[INFO] ------------------------------------------------------------------------
-
[INFO] Total time: 8.325s
-
[INFO] Finished at: Wed Nov 23 11:22:35 CST 2011
-
[INFO] Final Memory: 11M/103M
-
[INFO] ------------------------------------------------------------------------
-
N:\workshop>
2. Maven生成的Web项目的结构
Maven 会生成“Maven Standard Web Application Directory Layout“. See following diagram :
A new super clean “web.xml” file is created under “N:\workshop\helloworldjersey\src\main\webapp\WEB-INF” folder.
File : web.xml- <!DOCTYPE web-app PUBLIC
-
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
-
"" >
-
-
<web-app>
-
<display-name>Archetype Created Web Application</display-name>
-
</web-app>
3. pom.xmlRefer to the generated pom.xml file, the tag “packaging” is “war“, when build with Maven, this project will group it into a war file for deployment.
File : pom.xml- <project xmlns=""
-
xmlns:xsi=""
-
xsi:schemaLocation="
-
">
-
<modelVersion>4.0.0</modelVersion>
-
<groupId>com.mkyong.core</groupId>
-
<artifactId>mkyongweb-core</artifactId>
-
<packaging>war</packaging>
-
<version>1.0-SNAPSHOT</version>
-
<name>mkyongweb-core Maven Webapp</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>
-
<build>
-
<finalName>mkyongweb-core</finalName>
-
</build>
-
</project>
Done. Maven generated a standard web application project structure and a simple web.xml file.
4. mvn eclipse:eclipse -Dwtpversion=2.0
将maven生成的java项目转化为支持eclipse的java项目只需要执行以下命令 :
对于web项目,你需要额外的参数才能够让它支持Eclipse’s wtp, 所以为了将maven生成的web项目转化为支持eclipse的项目,需要执行以下命令 :
- mvn eclipse:eclipse -Dwtpversion=2.0
5. Eclipse WTP
Standard Eclipse’s “.classpath” and “.project” files are created. And you will noticed a new “.setting” folder is created and inside contains “org.eclipse.wst.common.component” and “org.eclipse.wst.common.project.facet.core.xml“, both files for WTP or Faces support in Eclipse.
6. Import into Eclipse IDE
Now, you have everything what a Eclipse web application want, so, you can start import your Maven based web application into Eclipse IDE.
Steps :
In Eclipse IDE, menu bar , File -> Import… -> General -> Existing Projects into Workspace -> select root directory (select your project folder) -> Done.------------------------------------------------------------------------------
导入后需要右击项目--maven--enable maven dependence
有可能由于eclipse,wtp的版本不一样,在项目名前面显示一个红叉。
可以通过eclipse创建一个动态网站项目,然后将.setting文件夹中的文件进行替换。
阅读(4420) | 评论(0) | 转发(0) |