便于后期的维护,我们一般会进行分层开发,基于Maven3开发。
system-parent
|—-pom.xml
|—-system-domain
|—-pom.xml
|—-system-dao
|—-pom.xml
|—-system-service
|—-pom.xml
|—-system-web
|—-pom.xml
网络问题可能会出现:
maven “Generating project in Batch mode”问题的解决
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
这句话的命令是创建一个默认的项目,但我在执行这个命令时,命令行会停在
[INFO] Generating project in Batch mode
增加一个-X参数,可以查看详细信息
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false -X
可以看到,程序停在了下面这一行。
[DEBUG] Searching for remote catalog: http://repo1.maven.org/maven2/archetype-catalog.xml
去查询这个文件的时候网络比较差或者其他原因,导致挂在那里。
解决方法很简单。
1. 把上述地址复制到浏览器中,下载这个文件到本地。
2. 把文件archetype-catalog.xml复制到目录.m2\repository\org\apache\maven\archetype\archetype-catalog\2.2下面。
3. 在上述命令后增加参数-DarchetypeCatalog=local,变成读取本地文件即可。
mvn archetype:generate -DgroupId=me.gacl -DartifactId=system-parent -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false -DarchetypeCatalog=local
将src文件夹删除,然后修改pom.xml文件,将jar修改为pom,pom表示它是一个被继承的模块
- domain
mvn archetype:generate -DgroupId=me.gacl -DartifactId=system-domain -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false -DarchetypeCatalog=local
- service
mvn archetype:generate -DgroupId=me.gacl -DartifactId=system-service -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false -DarchetypeCatalog=local
- dao
mvn archetype:generate -DgroupId=me.gacl -DartifactId=system-dao -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false -DarchetypeCatalog=local
- web
mvn archetype:generate -DgroupId=me.gacl -DartifactId=system-web -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false -DarchetypeCatalog=local
然后就好了!
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>me.gacl</groupId>
<artifactId>system-parent</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>system-parent</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<modules>
<module>system-domain</module>
<module>system-dao</module>
<module>system-service</module>
<module>system-web</module>
</modules>
</project>
<?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>me.gacl</groupId>
<artifactId>system-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>system-domain</artifactId>
<packaging>jar</packaging>
<name>system-domain</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
<?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>me.gacl</groupId>
<artifactId>system-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>system-dao</artifactId>
<packaging>jar</packaging>
<name>system-dao</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>me.gacl</groupId>
<artifactId>system-domain</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
<?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>me.gacl</groupId>
<artifactId>system-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>me.gacl</groupId>
<artifactId>system-service</artifactId>
<version>1.0-SNAPSHOT</version>
<name>system-service</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>me.gacl</groupId>
<artifactId>system-dao</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
<?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>me.gacl</groupId>
<artifactId>system-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>me.gacl</groupId>
<artifactId>system-web</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>system-web 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>
<dependency>
<groupId>me.gacl</groupId>
<artifactId>system-service</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<finalName>system-web</finalName>
<plugins>
<!--配置Jetty插件-->
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
最后编译
mvn clean install
在system-web目录下多出了target目录
启动项目
mvn jetty:run
最后导入IDE项目开发!