类路径中不包含本地jar(`< scope> system< / scope>`) [英] Local jars are not included in class path (`<scope>system</scope>`)

查看:448
本文介绍了类路径中不包含本地jar(`< scope> system< / scope>`)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用maven和eclipse构建我的应用程序。
我依赖于我本地机器上的第三方罐子。
这里是我的pom.xml

I am trying to build my application using maven and eclipse. I have dependencies on 3rd party jars which are on my local machine. here is my pom.xml

<dependency>
    <groupId>sourceforge.net</groupId>
   <artifactId>zipdiff</artifactId>
   <version>0.4</version>
   <scope>system</scope>
   <systemPath>C:/gelcap/lib/zipdiff-0.4.jar</systemPath>
</dependency>

<dependency>
    <groupId>log4j</groupId>
   <artifactId>log4j</artifactId>
   <version>1.2.11</version>
</dependency>

当我运行mvn时:安装它会为我的项目创建war文件。
但问题是它不包括zipdiff.jar文件到web-inf / lib文件夹它只包含下载的文件。我需要包括从我的本地系统复制文件,但maven忽略它们。
我没有想到为什么maven不包括系统范围的文件到我的war文件。
请告诉我如何解决这个问题。
提前致谢

when i run mvn : install it creates war file for my project. But problem is it does not include zipdiff.jar file to the web-inf/lib folder it only includes the files which are downloaded. I need to include copy the files from my local system also but maven ignores them. I have not got any thought why it is happening why maven is not including files with system scope to my war file. Please give me any idea how this problem can be resolved. Thanks in advance

推荐答案

对于系统范围,容器应提供人工制品。来自 maven docs

With "system" scope, the container is expected to provide the artefact. From the maven docs:


提供

这很像编译,但表明你期望JDK或
容器在
运行时提供依赖性。例如,在为Java
企业版构建
Web应用程序时,您可以将Servlet API和
相关Java EE API的
依赖关系设置为提供的范围
因为Web容器提供
这些类。这个范围只有
可用于编译和测试
类路径,并且不具有传递性。

This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.

[...]

系统

此范围与提供的类似,只是您必须提供
明确包含
的JAR。工件总是
可用,并且不会在
存储库中查找。

This scope is similar to provided except that you have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository.

使用系统范围,您向war插件指示容器将提供此依赖项。由于这不是您打算做的,最简单的解决方案是将人工制品放在存储库中,如果您有本地maven存储库,或者您自己的内部网上的maven存储库(如果有的话)。

By using a system scope, you are indicating to the war plugin that the container will provide this dependency. Since this is not what you are intending to do, the simplest solution is to put the artefact in a repository, either your local maven repository, or your own maven repo on your intranet, if you have one.

install:install-file 目标可用于将单个文件(无POM)安装到本地存储库。执行此操作后,将依赖关系类型更改为compile并删除systemPath元素。

The install:install-file goal can be used to install a single file (without POM) to your local repository. After doing this, change the dependency type to "compile" and remove the "systemPath" element.

在我的日常工作中,我们使用 Nexus 在我们的Intranet上管理公司范围的存储库。您可以为自己的人工制品和第三方人工制品分别拥有存储库。 Nexus还充当代理,从外部存储库缓存伪像,加快构建速度。这意味着只有使用其他repos中不可用的新依赖项的开发人员必须上传 - 之后,所有其他开发人员都可以使用它 - 他们可以从SCM签出并构建,而不必担心依赖项所在的位置。

In my day job, we use Nexus to manage a company-wide repository on our intranet. You can have separate repositories for your own artefacts, vs third party artefacts. Nexus also acts as a proxy, caching artefacts from external repositories, speeding up the build quite a bit. This means that only the developer that uses a new dependency that is not available in the other repos has to upload - after that, all the other devs can use it - they can checkout from SCM and build without worrying about where the dependencies are located.

这篇关于类路径中不包含本地jar(`&lt; scope&gt; system&lt; / scope&gt;`)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆