- 创建聚合模块(工程的父模块,应该是管理项目用的)。选择菜单项 File—>New—>Other,在弹出的对话框中选择Maven下的Maven Project,然后单击Next按钮,在弹出的New Maven Project 对话框中,使用默认选项,单击Next 按钮,此时m2eclipse 会提示我们选择一个Archetype。这里选择maven-archetype-quickstart,随后按照提示创建Maven聚合模块 app-parent,此处需要在pom文件中修改 <packaging>pom</packaging>。
- 创建maven模块。app-common, app-main,过程同上。
- 创建maven web模块 ,创建时选择Archetype时应选择 maven-archetype-webapp ,app-web
- 在web模块的pom文件中添加依赖,并添加tomcat插件;
<?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> <artifactId>app-parent</artifactId> <groupId>com.java.app</groupId> <version>0.0.1-SNAPSHOT</version> </parent> <groupId>com.java.app</groupId> <artifactId>app-web</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <name>app-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>com.java.app</groupId> <artifactId>app-common</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> <dependency> <groupId>com.java.app</groupId> <artifactId>app-main</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> <dependency> <groupId>com.java.app</groupId> <artifactId>app-common</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> </dependencies> <build> <finalName>app-web</finalName> <outputDirectory>src/main/webapp/WEB-INF/classes</outputDirectory> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.2</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.6</source> <target>1.6</target> <encoding>UTF-8</encoding> </configuration> </plugin> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat6-maven-plugin</artifactId> <version>2.0-beta-1</version> <configuration> <contextReloadable>false</contextReloadable> <port>8080</port> <uriEncoding>UTF-8</uriEncoding> <path>/app-web</path> </configuration> </plugin> </plugins> </pluginManagement> </build> </project>
- clean tomcat6:run 启动
- 访问http://localhost:8080/app-web/
- 完整项目结构
eclipse创建maven项目
最新推荐文章于 2021-07-22 23:00:25 发布