具有依赖项的Maven 2程序集:作用域“系统"下的jar不包含 [英] Maven 2 assembly with dependencies: jar under scope "system" not included

查看:122
本文介绍了具有依赖项的Maven 2程序集:作用域“系统"下的jar不包含的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用maven-assembly插件创建我的应用程序的jar,包括其依赖项,如下所示:

I am using maven-assembly plugin to create a jar of my application, including its dependencies as follows:

<assembly>
    <id>macosx</id>
    <formats>
       <format>tar.gz</format>
       <format>dir</format>
    </formats>
    <dependencySets>
        <dependencySet>
            <includes>
                <include>*:jar</include>
            </includes>
            <outputDirectory>lib</outputDirectory>
        </dependencySet>
    </dependencySets>
</assembly>

(我省略了与问题无关的其他内容)

(I omitted some other stuff that is not related to the question)

到目前为止,它已经很好地工作了,因为它创建了一个具有所有依赖项的lib目录.但是,我最近添加了一个范围为system的新依赖项,它不会将其复制到lib输出目录中.我肯定在这里缺少一些基本的东西,所以我寻求帮助.

So far this has worked fine because it creates a lib directory with all dependencies. However, I recently added a new dependency whose scope is system, and it does not copy it to the lib output directory. i must be missing something basic here, so I call for help.

我刚刚添加的依赖项是:

The dependency that I just added is:

<dependency>
  <groupId>sourceforge.jchart2d</groupId>
  <artifactId>jchart2d</artifactId>
  <version>3.1.0</version>
  <scope>system</scope>
  <systemPath>${project.basedir}/external/jchart2d-3.1.0.jar</systemPath>
</dependency>

我能够包括此依赖项的唯一方法是在Assembly元素中添加以下内容:

The only way I was able to include this dependency was by adding the following to the assembly element:

<files>
    <file>
        <source>external/jchart2d-3.1.0.jar</source>
        <outputDirectory>lib</outputDirectory>
    </file>
</files>

但是,这迫使我在重命名此jar时更改pom和汇编文件(如果有的话).而且,这似乎是错误的.

However, this forces me to change the pom and the assembly file whenever this jar is renamed, if ever. Also, it seems just wrong.

我尝试在dependencySets<include>sourceforge.jchart2d:jchart2d</include>中使用<scope>runtime</scope>并没有运气.

I have tried with <scope>runtime</scope> in the dependencySets and <include>sourceforge.jchart2d:jchart2d</include> with no luck.

那么,如何在Maven 2中的程序集中包含system作用域的jar?

So how do you include a system scoped jar to your assembly file in maven 2?

非常感谢

推荐答案

我不惊讶未添加系统范围的依赖项(毕竟,必须通过定义显式提供具有系统范围的依赖项).实际上,如果您真的不想将该依赖项放在本地存储库中(例如,因为您想将其作为项目的一部分进行分发),这就是我要做的:

I'm not surprised that system scope dependencies are not added (after all, dependencies with a system scope must be explicitly provided by definition). Actually, if you really don't want to put that dependency in your local repository (for example because you want to distribute it as part of your project), this is what I would do:

  • 我将依赖项放在项目本地的文件系统存储库"中.
  • 我会这样在我的pom.xml中声明该存储库:

<repositories>
  <repository>
    <id>my</id>
    <url>file://${basedir}/my-repo</url>
  </repository>
</repositories>

  • 我只会声明没有system范围的工件,这只是麻烦的来源:

  • I would just declare the artifact without the system scope, this is just a source of troubles:

    <dependency>
      <groupId>sourceforge.jchart2d</groupId>
      <artifactId>jchart2d</artifactId>
      <version>3.1.0</version>
    </dependency>
    

  • 我不确定100%会满足您的需求,但我认为这是比使用系统范围更好的解决方案.

    I'm not 100% sure this will suit your needs but I think it's a better solution than using the system scope.

    更新:我应该在原始答案中提到这一点,现在正在对其进行修复.要在基于文件的存储库中安装第三方库,请将install:install-file

    Update: I should have mentioned that in my original answer and I'm fixing it now. To install a third party library in the file-based repository, use install:install-file with the localRepositoryPath parameter:

    mvn install:install-file -Dfile=<path-to-file> \
                             -DgroupId=<myGroup> \
                             -DartifactId=<myArtifactId> \
                             -Dversion=<myVersion> \
                             -Dpackaging=<myPackaging> \
                             -DlocalRepositoryPath=<path-to-my-repo>
    

    您可以按原样将其粘贴在* nix shell中.在Windows上,删除"\"并将所有内容放在一行中.

    You can paste this as is in a *nix shell. On windows, remove the "\" and put everything on a single line.

    这篇关于具有依赖项的Maven 2程序集:作用域“系统"下的jar不包含的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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