maven配置
下载:https://maven.apache.org/download.cgi
下载这个(apache-maven-3.9.0-bin.zip)
------------------------------------------------------------------
环境变量配置
MAVEN_HOME E:\IDEA\apache-maven-3.9.0
path 增加 %MAVEN_HOME%\bin
E:\IDEA\apache-maven-3.9.0\conf\settings.xml 要修改的地方
1 | <localRepository>E:\IDEA\maven-repository</localRepository> |
1 2 3 4 5 6 7 | <mirror> <id>aliyun</id> <name>aliyun</name> <mirrorOf>central</mirrorOf> <!-- 国内推荐阿里云的Maven镜像 --> <url>https: //maven.aliyun.com/repository/central</url> </mirror> |
1 2 3 4 5 6 7 8 9 10 11 12 | <profile> <id>jdk-19</id> <activation> <activeByDefault> true </activeByDefault> <jdk>19</jdk> </activation> <properties> <maven.compiler.source>19</maven.compiler.source> <maven.compiler.target>19</maven.compiler.target> <maven.compiler.compilerVersion>19</maven.compiler.compilerVersion> </properties> </profile> |
单个项目pom.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | <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>wtl.test</groupId> <artifactId>wtl</artifactId> <!-- 生成的包,有jar \ war, war用于web--> <packaging>war</packaging> <version>1.0-SNAPSHOT</version> <!-- 模块名称,多模块引用有用到--> <name>wtl Maven Webapp</name> <url>http: //maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <!-- compile 编译时需要用到该jar包(默认) --> <!-- test 编译Test时需要用到该jar包 --> <!-- runtime 编译时不需要,但运行时需要用到 --> <!-- provided 编译时需要用到,但运行时由JDK或某个服务器提供--> <scope>test</scope> </dependency> </dependencies> <build> <!-- 要填一个默认--> <defaultGoal>compile</defaultGoal> <!-- 编译后打包文件名,如这个会是wtl.war--> <finalName>wtl</finalName> <!-- 使用的编译插件--> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>3.3.1</version> </plugin> </plugins> </build> <properties> <!-- 编译的编码,中文要用UTF-8,这个是用于编译后的*. class 里的文件的中文,不是浏览器请求说的那个中文--> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <!-- 编译使用的JDK--> <maven.compiler.source>19</maven.compiler.source> <!-- 目标JDK--> <maven.compiler.target>19</maven.compiler.target> <java.version>19</java.version> <spring.version>5.0.2.RELEASE</spring.version> </properties> </project> |
===========================================================
多模块
模块的就可以简化为
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <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> <parent> <groupId>com.itranswarp.learnjava</groupId> <artifactId>parent</artifactId> <version>1.0</version> <relativePath>../parent/pom.xml</relativePath> </parent> <artifactId>module-a</artifactId> <packaging>jar</packaging> <name>module-a</name> </project> |
模块B依赖A这样写
1 2 3 4 5 6 7 | <dependencies> <dependency> <groupId>com.itranswarp.learnjava</groupId> <artifactId>module-b</artifactId> <version>1.0</version> </dependency> </dependencies> |
根级别的pom.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <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>com.itranswarp.learnjava</groupId> <artifactId>build</artifactId> <version>1.0</version> <packaging>pom</packaging> <name>build</name> <modules> <module>parent</module> <module>module-a</module> <module>module-b</module> <module>module-c</module> </modules> </project> |
1 2 3 4 5 6 7 | servlet5.0的依赖 <dependency> <groupId>jakarta.servlet</groupId> <artifactId>jakarta.servlet-api</artifactId> <version>5.0.0</version> <scope>provided</scope> </dependency> |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通