maven实践
由于maven的仓库⽼是忘,在这⾥做⼀下备忘录。
⽗⼯程和⼦⼯程的项⽬管理
以下案例是⼀个⽗⼯程和⼦⼯程之间的相互管理。
⽗⼯程:⽗⼯程⽤于管理所有的jar包和版本号。
⼦⼯程:⼦⼯程⽤于导⼊⽗⼯程中的所有jar包。
这是⼀个springMVC和mybatis学习的⼀个l⽂件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="/POM/4.0.0"
xsi="/2001/XMLSchema-instance"
schemaLocation="/POM/4.0.0 /xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion>
<groupId>com.ydlclass</groupId>
<artifactId>ssm</artifactId>
<version>1.0-SNAPSHOT</version>
<modules>
<module>Mybatis-01</module>
<module>spring-mvc</module>
</modules>
<!-- 如果该项⽬是javaweb项⽬打包⽅式要改成war包-->
<packaging>pom</packaging>
<!-- ⽗模块⽤于约束版本信息 -->
<properties>
<!-- ⽤于改变编码-->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>maven打包本地jar包
<mavenpiler.source>11</mavenpiler.source>
<mavenpiler.target>11</mavenpiler.target>
<junit.version>4.13.1</junit.version>
<mybatis.version>3.5.7</mybatis.version>
<mysql-connector-java.version>8.0.26</mysql-connector-java.version>
<lombok.version>1.18.22</lombok.version>
<logback.version>1.2.6</logback.version>
<servlet-api.version>4.0.1</servlet-api.version>
<springframework-version>5.2.18.RELEASE</springframework-version>
</properties>
<!--编译插件,bulid部分每个项⽬都要有-->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<!--suppress UnresolvedMavenProperty -->
<target>
${mavempiler.target}
</target>
<!--suppress UnresolvedMavenProperty -->
<source>${mavempiler.source}</source>
<encoding>utf-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
<!-- ⽤于依赖管理要⽤下⾯这个标签-->
<dependencyManagement>
<!-- 导⼊依赖-->
<dependencies>
<!-- 单元测试 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<!-- mybatis 核⼼ -->
<dependency>
<groupId&batis</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis.version}</version>
</dependency>
<!-- 数据库确定 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql-connector-java.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<!-- ⼀个springmvc的依赖会⾃动传递spring的依赖--> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${springframework-version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
下⾯是⼀个springMVC⽤于引⼊jar包l⽂件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="/POM/4.0.0"
xsi="/2001/XMLSchema-instance"
schemaLocation="/POM/4.0.0 /xsd/maven-4.0.0.xsd"> <parent>
<artifactId>ssm</artifactId>
<groupId>com.ydlclass</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-mvc</artifactId>
<packaging>war</packaging>
<!-- 构建插件-->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<!--suppress UnresolvedMavenProperty -->
<target>
${mavempiler.target}
</target>
<!--suppress UnresolvedMavenProperty -->
<source>${mavempiler.source}</source>
<encoding>utf-8</encoding>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
</dependencies>
</project>
如果⼦项⽬中已经引⼊了⽗项⽬中的jar包在⽗项⽬中有怎么⼀个效果。
maven的⼀些常见报错
Error:(14,3) java: 编码UTF-8的不可映射字符
如图,当我点击install的时候maven莫名其妙跳到其他的页⾯并且报错。
原因:
在我百度之后发现原因是在install之前maven会对本地代码进⾏⼀个什么test,所以我们只要把这个test关闭掉就可以了。
解决⽅法:
把对应项⽬的test关闭即可。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论