、下载maven
官方
:http://maven.apache.org/download.html
、解压即用,直接解压到指定目录
、配置环境变量跟Java一样
、配置settings.xml文件
<localRepository>D:/Maven/apache-maven-3.8.2-bin/maven-repositorylocalRepository>
<mirror>
<id>nexus-aliyunid>
<mirrorOf>centralmirrorOf>
<name>Nexus aliyunname>
<url>http://maven.aliyun.com/nexus/content/groups/publicurl>
mirror>
、检查配置是否成功
、配置IDEA的maven环境
、创建一个webapp的模板项目
第一次加载费时间---->可能会报错,有可能是因为网卡导致大概结果如下
编译运行直接点comile编译运行
<plugins>
<plugin>
<groupId>org.apache.tomcat.mavengroupId>
<artifactId>tomcat7-maven-pluginartifactId>
<version>2.1version>
<configuration>
<port>8081port>
<path>/testpath>
<uriEncoding>UTF-8uriEncoding>
<server>tomcat7server>
configuration>
plugin>
plugins>
、启动项目
、创建一个空maven项目叫maven_parent
、创建内部模块
创建效果图:》》》
、编写Maven_dao的java文件
Userdao.java
public class UserDao {
public static void test(){
System.out.println("UseDao。。。。。。。。。。。。。");
}
}
、编写Maven_service的java文件
Userservice.java
public class UserService {
public static void test(){
System.out.println("UserService........");
UserDao.test();
}
}
pom.xml增加在
<dependency>
<groupId>org.examplegroupId>
<artifactId>Maven_daoartifactId>
<version>1.0-SNAPSHOTversion>
<scope>compilescope>
dependency>
dependencies>
、编写Maven_controller的java文件
引入内容》》
<dependencies>
<dependency>
<groupId>junitgroupId>
<artifactId>junitartifactId>
<version>4.11version>
<scope>testscope>
dependency>
<dependency>
<groupId>javax.servletgroupId>
<artifactId>javax.servlet-apiartifactId>
<version>3.0.1version>
<scope>providedscope>
dependency>
<dependency>
<groupId>org.examplegroupId>
<artifactId>Maven_serviceartifactId>
<version>1.0-SNAPSHOTversion>
<scope>compilescope>
dependency>
dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.mavengroupId>
<artifactId>tomcat7-maven-pluginartifactId>
<version>2.1version>
<configuration>
<port>8081port>
<path>/webpath>
<uriEncoding>UTF-8uriEncoding>
<server>tomcat7server>
configuration>
plugin>
plugins>
java测试内容
import org.example.UserService;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/user")
public class Controller extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
UserService.test();
}
}
Maven_controller启动结果:》》
完工,一切的报错,都是细节的决定~