拓宽阅读

maven 包办理渠道-01-maven 入门介绍 + Maven、Gradle、Ant、Ivy、Bazel 和 SBT 的具体对比表格

maven 包办理渠道-02-windows 装置配置 + mac 装置配置

maven 包办理渠道-03-maven project maven 项目的创建入门

maven 包办理渠道-04-maven archetype 项目原型

maven 包办理渠道-05-multi module 多模块

maven 包办理渠道-06-常用技巧 实时更新快照/乱码问题/下载很慢/包依靠解决包抵触/如何导入本地 jar

maven 包办理渠道-07-plugins 常见插件介绍

maven 包办理渠道-08-nexus 自己搭建 maven 库房

实时更新快照

当您在运用 Idea 获取 快照(snapshot) Jar 包时,您可能不能当即获得它。

以下是解决方法:

翻开 Preference,查找 maven,并选择 Always update snapshots

乱码问题

mvn运转乱码问题

pom.xmlproperties 下增加以下内容:

<properties>
    <argLine>-Dfile.encoding=UTF-8</argLine>
</properties>

下载很慢

blog zh_CN

~/.m2/setting.xml 中增加:

<mirrors>
       <!-- 阿里云库房 -->
      <mirror>
           <id>alimaven</id>
           <mirrorOf>central</mirrorOf>
           <name>aliyun maven</name>
            <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
       </mirror>
</mirrors>

包依靠解决包抵触

有时候依靠其他的三方jar包较多,有些jar被重复引入且版别不一致。(比如slf4j-api.jar)

能够在某一个项目下运用 mvn dependency:tree

D:CODEotherframeworkframework-cache>mvn dependency:tree
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building framework :: Module :: Cache 1.0.2-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ framework-cache ---
[INFO] com.framework:framework-cache:jar:1.0.2-SNAPSHOT
[INFO] +- com.framework:framework-tool:jar:1.0.2-SNAPSHOT:compile
[INFO] |  +- com.framework:framework-common:jar:1.0.2-SNAPSHOT:compile
[INFO] |  |  +- org.apache.commons:commons-lang3:jar:3.3.2:compile
[INFO] |  |  +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] |  |  +- commons-codec:commons-codec:jar:1.10:compile
[INFO] |  |  - org.projectlombok:lombok:jar:1.16.8:compile
[INFO] |  +- org.apache.logging.log4j:log4j-api:jar:2.5:compile
[INFO] |  +- org.apache.logging.log4j:log4j-core:jar:2.5:compile
[INFO] |  +- com.alibaba:fastjson:jar:1.2.8:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.4.0:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.4.0:compile
[INFO] |  |  - com.fasterxml.jackson.core:jackson-core:jar:2.4.0:compile
[INFO] |  +- org.reflections:reflections:jar:0.9.10:compile
[INFO] |  |  +- com.google.guava:guava:jar:15.0:compile
[INFO] |  |  +- org.javassist:javassist:jar:3.20.0-GA:compile
[INFO] |  |  - com.google.code.findbugs:annotations:jar:2.0.1:compile
[INFO] |  - junit:junit:jar:4.12:compile
[INFO] |     - org.hamcrest:hamcrest-core:jar:1.3:compile
[INFO] +- org.springframework:spring-context:jar:4.2.3.RELEASE:compile
[INFO] |  +- org.springframework:spring-aop:jar:4.2.3.RELEASE:compile
[INFO] |  +- org.springframework:spring-beans:jar:4.2.3.RELEASE:compile
[INFO] |  +- org.springframework:spring-core:jar:4.2.3.RELEASE:compile
[INFO] |  |  - commons-logging:commons-logging:jar:1.2:compile
[INFO] |  - org.springframework:spring-expression:jar:4.2.3.RELEASE:compile
[INFO] +- org.springframework.data:spring-data-redis:jar:1.3.2.RELEASE:compile
[INFO] |  +- org.springframework:spring-context-support:jar:4.2.3.RELEASE:compile
[INFO] |  +- org.slf4j:slf4j-api:jar:1.7.5:compile
[INFO] |  - org.springframework:spring-tx:jar:4.2.3.RELEASE:compile
[INFO] +- redis.clients:jedis:jar:2.4.2:compile
[INFO] |  - org.apache.commons:commons-pool2:jar:2.0:compile
[INFO] +- aopalliance:aopalliance:jar:1.0:compile
[INFO] +- org.aspectj:aspectjweaver:jar:1.8.5:compile
[INFO] +- org.aspectj:aspectjrt:jar:1.8.5:compile
[INFO] - commons-net:commons-net:jar:3.5:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.927 s
[INFO] Finished at: 2017-01-24T10:57:41+08:00
[INFO] Final Memory: 15M/304M
[INFO] ------------------------------------------------------------------------
  • 扫除依靠

exclusion

如何导入本地 jar?

场景:有些 jar 文件中心库房没有。在 maven 项目中运用咱们就需要采纳一些技巧。

导入到本地库房

  • 导入到 nexus 库房

  • 导入到 maven 库房

maven增加sqlserver的jdbc驱动包

一、 在有 sqljdbc4.jar 的文件下

mvn install:install-file -Dfile=sqljdbc4.jar -Dpackaging=jar -DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc4 -Dversion=4.0

指令解释:mvn install:install-file -Dfile=”jar包的绝对路径” -Dpackaging=”文件打包方式” -DgroupId=groupid名 -DartifactId=artifactId名 -Dversion=jar版别

二、引入

<dependency>
    <groupId>com.microsoft.sqlserver</groupId>
    <artifactId>sqljdbc4</artifactId>
    <version>4.0</version>
</dependency>

指定绝对路径

Maven中运用本地JAR包

  1. 路径指定时运用 /, 为了跨渠道。

  2. 如果是 maven 多模块项目。能够运用相似如下的 jar 路径指定方式:

<dependency>
    <groupId>com.microsoft.sqlserver</groupId>
    <artifactId>sqljdbc4</artifactId>
    <version>4.0</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/../lib/sqljdbc4.jar</systemPath>
</dependency>

通过编译参数

既运用maven编译,又运用lib下的Jar包
本文由博客一文多发渠道 OpenWrite 发布!