`

使用命令行快速创建Maven多模块项目

阅读更多

使用命令行快速创建Maven多模块项目

 

1.创建父模块

mvn archetype:generate -DgroupId=name.isgodonto -DartifactId=auth-all -Dversion=1.0.0-SNAPSHOT -Dpackage=name.isgodonto -DarchetypeArtifactId=maven-archetype-site-simple -DarchetypeGroupId=org.apache.maven.archetypes  -DinteractiveMode=false

  

2.创建子模块

cd auth-all
mvn archetype:generate -DgroupId=name.isgodonto -DartifactId=auth-dal -Dversion=1.0.0-SNAPSHOT -Dpackage=name.isgodonto -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeGroupId=org.apache.maven.archetypes  -DinteractiveMode=false

mvn archetype:generate -DgroupId=name.isgodonto -DartifactId=auth-biz -Dversion=1.0.0-SNAPSHOT -Dpackage=name.isgodonto -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeGroupId=org.apache.maven.archetypes  -DinteractiveMode=false

mvn archetype:generate -DgroupId=name.isgodonto -DartifactId=auth-web -Dversion=1.0.0-SNAPSHOT -Dpackage=name.isgodonto -DarchetypeArtifactId=maven-archetype-webapp -DarchetypeGroupId=org.apache.maven.archetypes  -DinteractiveMode=false

 3.目录结构:

auth-all:父(聚合)模块

auth-dal:数据访问模块

auth-biz:业务模块,依赖于auth-dal

auth-web:web模块,依赖于auth-biz

 

4.pom文件调整如下:

1)auth-all的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>name.isgodonto</groupId>
  <artifactId>auth-all</artifactId>
  <version>1.0.0-SNAPSHOT</version>
  <packaging>pom</packaging>

  <properties>
  	<auth.version>1.0.0-SNAPSHOT</auth.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <jetty.version>8.1.13.v20130916</jetty.version>
  </properties>
  
  <modules>
    <module>auth-dal</module>
    <module>auth-biz</module>
    <module>auth-web</module>
  </modules>
  
  <dependencyManagement>
  	<dependencies>
  		<!-- ================================================= -->
        <!-- 模块间依赖   -->
        <!-- ================================================= -->
  		<dependency>
  			<groupId>name.isgodonto</groupId>
  			 <artifactId>auth-dal</artifactId>
  			 <version>${auth.version}</version>
  		</dependency>
  		<dependency>
  			<groupId>name.isgodonto</groupId>
  			 <artifactId>auth-biz</artifactId>
  			 <version>${auth.version}</version>
  		</dependency>
  		<dependency>
  			<groupId>name.isgodonto</groupId>
  			 <artifactId>auth-web</artifactId>
  			 <version>${auth.version}</version>
  		</dependency>
  	</dependencies>
  </dependencyManagement>
  
  <build>
  	<pluginManagement>
  		<plugins>
  			<plugin>
  				<groupId>org.mortbay.jetty</groupId>
               	<artifactId>jetty-maven-plugin</artifactId>
               <version>${jetty.version}</version>
  			</plugin>
  		</plugins>
  	</pluginManagement>
  </build>
  
</project>

 

 2)all-dal的pom.xml:

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>name.isgodonto</groupId>
    <artifactId>auth-all</artifactId>
    <version>1.0.0-SNAPSHOT</version>
  </parent>
  
  <artifactId>auth-dal</artifactId>
  <name>auth-dal</name>
</project>

 

 3)admin-biz的pom.xml:

<?xml version="1.0"?>
<project
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
	xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>name.isgodonto</groupId>
		<artifactId>auth-all</artifactId>
		<version>1.0.0-SNAPSHOT</version>
	</parent>

	<artifactId>auth-biz</artifactId>
	<name>auth-biz</name>

	<dependencies>
		<dependency>
			<groupId>name.isgodonto</groupId>
			<artifactId>auth-dal</artifactId>
		</dependency>
	</dependencies>
</project>

 

4)auth-web的pom.xml:

<?xml version="1.0"?>
<project
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
	xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>name.isgodonto</groupId>
		<artifactId>auth-all</artifactId>
		<version>1.0.0-SNAPSHOT</version>
	</parent>

	<artifactId>auth-web</artifactId>
	<packaging>war</packaging>

	<dependencies>
		<dependency>
			<groupId>name.isgodonto</groupId>
			<artifactId>auth-biz</artifactId>
		</dependency>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>javax.servlet-api</artifactId>
			<version>3.1.0</version>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.mortbay.jetty</groupId>
				<artifactId>jetty-maven-plugin</artifactId>
				<configuration>
					<webApp>
						<contextPath>/</contextPath>
					</webApp>
					<scanIntervalSeconds>5</scanIntervalSeconds>
					<stopKey>myapp</stopKey>
					<stopKey>9999</stopKey>
					<connectors>
						<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
							<port>80</port>
							<maxIdleTime>60000</maxIdleTime>
						</connector>
					</connectors>
					<requestLog implementation="org.eclipse.jetty.server.NCSARequestLog">
						<filename>target/access.log</filename>
						<retainDays>90</retainDays>
						<append>false</append>
						<extended>false</extended>
						<logTimeZone>GMT+8:00</logTimeZone>
					</requestLog>
				</configuration>
			</plugin>
		</plugins>
		<finalName>auth-web</finalName>
	</build>
</project>

 

 

 5.运行项目:

在auth-all下执行以下命令安装包到本地仓库:

mvn clean install -pl auth-web -am

 在auth-web下执行以下命令启动jetty容器:

mvn jetty:run

 在浏览器输入http://localhost,看到"Hello World!"就成功了!

 

 

  • 大小: 8.4 KB
1
2
分享到:
评论
2 楼 Tiro_Li 2015-11-24  

-DarchetypeVersion=1.1改成-DarchetypeVersion=1.0,或删除版本会自动获取最新发布版
1 楼 nicegege 2015-11-24  
mvn archetype:generate -DgroupId=name.isgodonto -DartifactId=auth-web -Dversion=1.0.0-SNAPSHOT -Dpackage=name.isgodonto -DarchetypeArtifactId=maven-archetype-webapp  -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeVersion=1.1 -DinteractiveMode=false   执行生成web项目时,报错了。

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2
.3:generate (default-cli) on project auth-all: The desired archetype does not ex
ist (org.apache.maven.archetypes:maven-archetype-webapp:1.1) -> [Help 1]

怎么解决的?

相关推荐

Global site tag (gtag.js) - Google Analytics