关于后端:maven-技巧实时更新快照乱码问题下载很慢包依赖解决包冲突如何导入本地-jar

2次阅读

共计 4442 个字符,预计需要花费 12 分钟才能阅读完成。

拓展浏览

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:\CODE\other\framework\framework-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 公布!

正文完
 0