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 要修改的地方
<localRepository>E:\IDEA\maven-repository</localRepository>
<mirror> <id>aliyun</id> <name>aliyun</name> <mirrorOf>central</mirrorOf> <!-- 国内推荐阿里云的Maven镜像 --> <url>https://maven.aliyun.com/repository/central</url> </mirror>
<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
<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>
===========================================================
多模块
模块的就可以简化为
<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这样写
<dependencies> <dependency> <groupId>com.itranswarp.learnjava</groupId> <artifactId>module-b</artifactId> <version>1.0</version> </dependency> </dependencies>
根级别的pom.xml
<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>
servlet5.0的依赖 <dependency> <groupId>jakarta.servlet</groupId> <artifactId>jakarta.servlet-api</artifactId> <version>5.0.0</version> <scope>provided</scope> </dependency>