使用maven搭建ssm框架

xiaoxiao2021-02-28  20

环境:Eclipse+Maven+jdk1.8+Tomcat8

刚开始用的myeclipse2014+tomcat6,7+jdk1.8然后中间出现了各种各样的问题,暴力全部卸载,重新装的。

一、安装maven

官网下载https://maven.apache.org/download.cgi

选择其中一个下载即可。

下载后将其解压到D:\develop\Java\apache-maven-3.5.3

设置环境变量PATH中加入%MAVEN_HOME%\bin,新建系统变量,变量名:MAVEN_HOME,变量值:D:\develop\Java\apache-maven-3.5.3

配置成功后使用命令mvn -v查看出现:

二、设置maven数据仓库:

maven的数据仓库默认位置为c:用户\lenovo\.m2\repository下,将默认的位置改为D:\develop\maven-repository\maven-jar,更改D:\develop\Java\apache-maven-3.5.3\conf下的setting.xml文件中的默认仓库配置:

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <localRepository>D:\develop\maven-repository\maven-jar</localRepository>

设置mirror标签

<mirrors> <mirror> <id>nexus-aliyun</id> <mirrorOf>*</mirrorOf> <name>Nexus aliyun</name> <url>http://maven.aliyun.com/nexus/content/groups/public</url> </mirror>

默认镜像的位置。

maven的默认jre为1.5,会出现很多问题,所以修改属性:

<profiles> <profile> <id>jdk-1.8</id> <activation> <activeByDefault>true</activeByDefault> <jdk>1.8</jdk> </activation> <properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion> </properties> </profile>

完成后保存,并将setting文件复制一份放在D:\develop\maven-repository\maven-jar下面。

三、eclipse中集成maven

windows->preferences->maven->java->installed JREs

windows->preferences->maven->installtions->add

windows->preferences->maven->user settings

全局设置是使用maven中的setting,用户设置中使用的是repository中的setting文件。

四、eclipse中创建maven项目

五、整合搭建SSM(Spring+SpringMVC+Mybaits)

修改pom文件:

<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>Human-Resources</groupId> <artifactId>Display</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>Display Maven Webapp</name> <url>http://maven.apache.org</url> <!-- 版本参量设置--> <properties> <spring-version>4.2.5.RELEASE</spring-version> <mybatis-version>3.4.1</mybatis-version> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <!-- spring核心包 start--> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring-version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>${spring-version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring-version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring-version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring-version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>${spring-version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>${spring-version}</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>1.8.5</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>${spring-version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>${spring-version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>${spring-version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId> <version>${spring-version}</version> </dependency> <!-- spring核心包 end--> <!-- mybatis核心包 --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>${mybatis-version}</version> </dependency> <!-- mybatis-spring包 --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>1.3.0</version> </dependency> <!-- logback 日志 --> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.1.7</version> </dependency> <!-- servlet --> <dependency> <groupId>javax.servlet</groupId> <artifactId>jsp-api</artifactId> <version>2.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> <scope>provided</scope> </dependency> <!-- mysql --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.26</version> </dependency> <!-- druid数据库连接池 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.0.18</version> </dependency> <!--json解析包 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.3</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>2.5.4</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.5.4</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-annotations</artifactId> <version>2.5.4</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> <finalName>Display</finalName> </build> </project>

参考博文:

https://www.cnblogs.com/knightsu/p/knightsu.html

https://www.cnblogs.com/vikezhu/p/6655557.html

转载请注明原文地址: https://www.6miu.com/read-2150344.html

最新回复(0)