求春风十里百度云资源不如你百度云

25487人阅读
编程(13)
在Maven项目中使用本地JAR包有两种方法:
1. 使用system scope
&dependencies&
&dependency&
&groupId&org.richard&/groupId&
&artifactId&my-jar&/artifactId&
&version&1.0&/version&
&scope&system&/scope&
&systemPath&${project.basedir}/lib/my-jar.jar&/systemPath&
&/dependency&
&/dependencies&
system scope引入的包,在使用jar-with-dependencies打包时将不会被包含,可以使用resources将本地包打进jar-with-dependencies
&groupId&org.apache.maven.plugins&/groupId&
&artifactId&maven-shade-plugin&/artifactId&
&executions&
&execution&
&id&make-assembly&/id&
&phase&package&/phase&
&goal&shade&/goal&
&configuration&
&descriptorRefs&
&descriptorRef&jar-with-dependencies&/descriptorRef&
&/descriptorRefs&
&finalName&xxx-jar-with-dependencies&/finalName&
&/configuration&
&/execution&
&/executions&
&/plugins&
&resources&
&resource&
&targetPath&lib/&/targetPath&
&directory&lib/&/directory&
&includes&
&include&**/my-jar.jar&/include&
&/includes&
&/resource&
&/resources&
生成的xxx-jar-with-dependencies.jar中,将会包含lib目录以及my-jar.jar,并且能够被在执行的时候被找到。
有的时候这种方法会实效,比如JDBCDriver在声明的时候Class.forName(&xxx.Driver&)就会说找不到类,用下面两种方法就可以。
2. 将jar包安装到本地repository中
mvn install:install-file -Dfile=my-jar.jar -DgroupId=org.richard -DartifactId=my-jar -Dversion=1.0 -Dpackaging=jar
&3. 添加&in project repository,在新机器上执行时就不用运行mvn install:install-file命令了
&repository&
&id&in-project&/id&
&name&In Project Repo&/name&
&url&file://${project.basedir}/lib&/url&
&/repository&
&dependency&
&groupId&org.richard&/groupId&
&artifactId&my-jar&/artifactId&
&version&1.0&/version&
&/dependency&
你的jar包及路径必须严格遵循格式:
/groupId/artifactId/version/artifactId-verion.jar
本例中: lib/org/richard/my-jar/1.0/my-jar-1.0.jar
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:296533次
积分:3432
积分:3432
排名:第7480名
原创:46篇
转载:165篇
评论:19条
(1)(1)(4)(5)(2)(1)(2)(1)(2)(1)(2)(2)(8)(3)(12)(3)(7)(3)(2)(2)(1)(4)(2)(4)(34)(1)(4)(6)(1)(1)(1)(3)(2)(7)(3)(1)(5)(1)(1)(5)(5)(8)(6)(16)(2)(11)(8)(5)(1)maven-dependency-plugin插件的使用 - 刘刚的空间 - ITeye技术网站
博客分类:
是处理与依赖相关的插件。它有很多可用的goal,大部分是和依赖构建、分析和解决相关的goal,这部分goal可以直接用maven的命令操作,例如:mvn dependency:tree、mvn dependency:analyze;这类操作在平时的maven应用中很少会用到。这里主要介绍除此之外的、用得最多的几个操作:copy, copy-dependencies和它们对应的unpack, unpack-dependencies
首先声明插件:
&groupId&org.apache.maven.plugins&/groupId&
&artifactId&maven-dependency-plugin&/artifactId&
&version&2.8&/version&
&/plugins&
copy 和 unpack
copy操作可以用来将某个(些)maven artifact(s)拷贝到某个目录下。添加phase和goal如下:
&groupId&org.apache.maven.plugins&/groupId&
&artifactId&maven-dependency-plugin&/artifactId&
&version&2.8&/version&
&executions&
&execution&
&phase&package&/phase&
&goal&copy&/goal&
&/execution&
&/executions&
&/plugins&
然后就是配置,copy可以的配置的项比较多,详细的请参考:。下面是一些常用项说明:
Description
Collection of ArtifactItems to work on. (ArtifactItem contains groupId, artifactId, version, type, classifier, outputDirectory, destFileName and overWrite.) See
for details.
Default output location used for mojo, unless overridden in ArtifactItem.Default value is: ${project.build.directory}/dependency.User property is: outputDirectory.
Prepend artifact groupId during copyDefault value is: false.User property is: mdep.prependGroupId.
prependGroupId: 用来指示拷出来的library名字需要不需要加上groupId,默认是不加
outputDirectory: 用来指定拷出后Libraries的存放地
这里除了artifactItems没有默认值,需要指定外,所有其他的选项都可以被忽略:
&configuration&
&artifactItems&
&artifactItem&
&groupId&junit&/groupId&
&artifactId&junit&/artifactId&
&version&4.11&/version&
&/artifactItem&
&/artifactItems&
&/configuration&
以上配置会将junit包拷到target/dependency目录下,文件名为:junit-4.11.jar。
如果想把它拷到lib目录下,可以如下配置:
&configuration&
&artifactItems&
&artifactItem&
&groupId&junit&/groupId&
&artifactId&junit&/artifactId&
&version&4.11&/version&
&/artifactItem&
&/artifactItems&
&outputDirectory&lib&/outputDirectory&
&/configuration&
&configuration&
&artifactItems&
&artifactItem&
&groupId&junit&/groupId&
&artifactId&junit&/artifactId&
&version&4.11&/version&
&outputDirectory&lib&/outputDirectory&
&/artifactItem&
&/artifactItems&
&/configuration&
根据上面的说明,artifactItem里可以有以下几个参数:
artifactId
classifier
outputDirectory
destFileName
同样的参数,artifactItem里的优先级更高,例如:
&configuration&
&artifactItems&
&artifactItem&
&groupId&junit&/groupId&
&artifactId&junit&/artifactId&
&version&4.11&/version&
&/artifactItem&
&artifactItem&
&groupId&org.slf4j&/groupId&
&artifactId&slf4j-log4j12&/artifactId&
&version&1.7.7&/version&
&outputDirectory&lib2&/outputDirectory&
&/artifactItem&
&/artifactItems&
&outputDirectory&lib&/outputDirectory&
&/configuration&
其中junit会拷到lib目录下,因为它没有定义自己的outputDirectory;slf4j-log4j12会拷到lib2下,因为它定义了自己的outputDirectory。
unpack和copy类似,只不过它会把拷来的包解开,例如:
&executions&
&execution&
&phase&package&/phase&
&goal&unpack&/goal&
&/execution&
&/executions&
&configuration&
&artifactItems&
&artifactItem&
&groupId&junit&/groupId&
&artifactId&junit&/artifactId&
&version&4.11&/version&
&/artifactItem&
&artifactItem&
&groupId&org.slf4j&/groupId&
&artifactId&slf4j-log4j12&/artifactId&
&version&1.7.7&/version&
&outputDirectory&lib2&/outputDirectory&
&/artifactItem&
&/artifactItems&
&outputDirectory&lib&/outputDirectory&
&/configuration&
则junit和slf4j-log4j12拷完以后,放到lib和lib2下的不再是Jar包,还是Jar包里的内容。
copy-dependencies 和 unpack-dependencies
上面介绍的copy 和 unpack操作是由要拷某个包,这个包需要具体指定要拷哪个包,与当前工程的依赖没有关系。copy-dependencies和它有点类似,但是它是用来拷当前工程的依赖包的,典型的,例如我们有一个web应用,当打成war包的时候,它所有的依赖也需要被打到应用中。
copy-dependencies的参数有很多,详细的可以参考:,但是几乎所有都有默认值。所以一个最简单的定义如下:
&groupId&org.apache.maven.plugins&/groupId&
&artifactId&maven-dependency-plugin&/artifactId&
&version&2.8&/version&
&executions&
&execution&
&phase&package&/phase&
&goal&copy-dependencies&/goal&
&/execution&
&/executions&
这里没有指定任何配置,所有的参数都用默认值,则当前工程的所有依赖(直接、间接的)都会被拷到target/dependency目录下。
也可以使用outputDirectory指定存放在。另外,以下几个参数可以控制哪些依赖将被拷出(或排除):
Description
Comma separated list of Artifact names to exclude.User property is: excludeArtifactIds.
Comma Separated list of Classifiers to exclude. Empty String indicates don't exclude anything (default).User property is: excludeClassifiers.
Comma separated list of GroupId Names to exclude.User property is: excludeGroupIds.
Scope to exclude. An Empty string indicates no scopes (default).User property is: excludeScope.
If we should exclude transitive dependenciesDefault value is: false.User property is: excludeTransitive.
Comma Separated list of Types to exclude. Empty String indicates don't exclude anything (default).User property is: excludeTypes.
Comma separated list of Artifact names to include.User property is: includeArtifactIds.
Comma Separated list of Classifiers to include. Empty String indicates include everything (default).User property is: includeClassifiers.
Comma separated list of GroupIds to include.User property is: includeGroupIds.
Scope to include. An Empty string indicates all scopes (default). The scopes being interpreted are the scopes as Maven sees them, not as specified in the pom. In summary:
runtime scope gives runtime and compile dependencies,
compile scope gives compile, provided, and system dependencies,
test (default) scope gives all dependencies,
provided scope just gives provided dependencies,
system scope just gives system dependencies.
User property is: includeScope.
Comma Separated list of Types to include. Empty String indicates include everything (default).User property is: includeTypes.
例如当前工程有以下依赖:
&dependencies&
&dependency&
&groupId&junit&/groupId&
&artifactId&junit&/artifactId&
&version&4.11&/version&
&scope&test&/scope&
&/dependency&
&dependency&
&groupId&org.slf4j&/groupId&
&artifactId&slf4j-log4j12&/artifactId&
&version&1.7.7&/version&
&scope&test&/scope&
&/dependency&
&dependency&
&groupId&org.apache.camel&/groupId&
&artifactId&camel-script&/artifactId&
&version&2.13.2&/version&
&/dependency&
&dependency&
&groupId&org.apache.camel&/groupId&
&artifactId&camel-spring&/artifactId&
&version&2.13.2&/version&
&/dependency&
&dependency&
&groupId&org.apache.camel&/groupId&
&artifactId&camel-xstream&/artifactId&
&version&2.13.2&/version&
&/dependency&
&dependency&
&groupId&org.springframework&/groupId&
&artifactId&spring-jms&/artifactId&
&version&3.2.4.RELEASE&/version&
&/dependency&
&dependency&
&groupId&org.springframework&/groupId&
&artifactId&spring-tx&/artifactId&
&version&3.2.4.RELEASE&/version&
&/dependency&
&dependency&
&groupId&org.apache.activemq&/groupId&
&artifactId&activemq-all&/artifactId&
&version&5.10.0&/version&
&/dependency&
&dependency&
&groupId&com.thoughtworks.xstream&/groupId&
&artifactId&xstream&/artifactId&
&version&1.4.7&/version&
&/dependency&
&dependency&
&groupId&org.ogce&/groupId&
&artifactId&xpp3&/artifactId&
&version&1.1.6&/version&
&/dependency&
&/dependencies&
要排除所有scope为test的依赖:
&groupId&org.apache.maven.plugins&/groupId&
&artifactId&maven-dependency-plugin&/artifactId&
&version&2.8&/version&
&executions&
&execution&
&phase&package&/phase&
&goal&copy-dependencies&/goal&
&/execution&
&/executions&
&configuration&
&includeScope&compile&/includeScope&
&/configuration&
注意:这里不能&excludeScope&test&/excludeScope&,这样会把所有compile级别的也排除。看下图:
Copied From:
scope/phase-&
说明:最左侧是表示dependency的scope级别,顶行表示maven的阶段,可以看出:compile级别的dependency会在所有阶段都被使用。
要排除所有camel的依赖,如下:
&configuration&
&excludeGroupIds&org.apache.camel&/excludeGroupIds&
&/configuration&
要排除除camel-spring外的所有其他依赖如下:
&configuration&
&includeArtifactIds&camel-spring&/includeArtifactIds&
&/configuration&
浏览 30107
liugang594
浏览: 583127 次
来自: 北京
你好。可以提供maven pom配置是怎么配置的?不知道你使用 ...
请问楼主一二三部分的代码都应该放在哪个函数体中。
学习了素人派
学习了。。。可是我们日常中用到的很少对不对?> 在eclipse的maven插件中搜寻本地仓库中的jar搜索不到的解决方案
在eclipse的maven插件中搜寻本地仓库中的jar搜索不到的解决方案
vip0758 & &
发布时间: & &
浏览:5 & &
回复:0 & &
悬赏:0.0希赛币
在eclipse的maven插件中搜索本地仓库中的jar搜索不到的解决方案
  之前,用过maven管理项目的童鞋都知道本地会有一个${User_Home}.m2/repository仓库 是用来存放jar包的地方。但是,在eclipse中的maven仓库中 搜索不到本地仓库中的jar包。
  原因是因为maven中的本地仓库的index索引没有更新,导致在eclipse的maven插件中搜索不到。
  解决方案:
  在eclipse中打开菜单 window-& show view –& other –& Maven -& maven repositories
  打开之后,选择local repositories –& local repository ,右击,选择Build index.
  更新完索引之后,在通过右键单击pom.xml文件选择maven –& add dependency 或者是打开pom.xml文件,选择dependencies –&add 时,就可以搜索到本地仓库的jar包了。
  如下图:
  如果想搜索公服上的jar
  就选择Global Repositories -&右击 update index. (此处更新比较慢,需要耐心等候)。
本问题标题:
本问题地址:
温馨提示:本问答中心的任何言论仅代表发言者个人的观点,与希赛网立场无关。请对您的言论负责,遵守中华人民共和国有关法律、法规。如果您的言论违反希赛网问答中心的规则,将会被删除。
暂无合适的专家
&&&&&&&&&&&&&&&
希赛网 版权所有 & &&maven配置本地jar包
在用maven做spring m项目的时候,开发过程中需要一个jar包,不过在maven官方库中没有找到jar包对应的pom文件依赖配置,所以不得已从网上下载了jar包(暂且重命名为AXP-apk-1.1.0.jar);
下面仍然需要在pom.xml文件中指定对该jar包的依赖项目名称为(AcrWeb),
第一步:在项目根目录下创建一个如下目录格式的文件:repo/AXP/AXP-apk/1.1.0,
把AXP-apk-1.1.0..jar这个jar包放到上面创建的文件1.1.0中,目录结构如图所示
第二步:配置pom.xml文件中的respository,配置如下
data-local
file://${project.basedir}/repo
第三步:配置pom.xml文件中的dependency
这样maven项目中可以使用自己下载的jar包了
(window.slotbydup=window.slotbydup || []).push({
id: '2467140',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467141',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467142',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467143',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467148',
container: s,
size: '1000,90',
display: 'inlay-fix'

我要回帖

更多关于 春风里不如你百度云 的文章

 

随机推荐