【问题标题】:Force Maven to Pick up Dependencies in Project Directory强制 Maven 在项目目录中获取依赖项
【发布时间】:2018-12-06 16:34:19
【问题描述】:

我正在使用 Maven 来管理我的依赖项,并试图从我的项目目录中提取一些专有的 jar 文件。 (是的,我知道,我是一个疯狂的白痴,他没有理解 Maven 的目的,并且永远不应该这样做。)在编译时,我收到关于指向项目目录中文件的典型警告。但是,指定的 jar 文件没有放在我的 .m2 目录中,因此,由于缺少依赖项,项目无法编译。

在 pom.xml 中:

<dependency>
<groupId>org.sample</groupId>
<artifactId>sample</artifactId>
<scope>system</scope>
<version>2.0.3</version>
<systemPath>${project.basedir}/WebContent/WEB-INF/lib/my_file.jar</systemPath>
<type>jar</type
<optional>true</optional>
</dependency>

问题是,我是否正确声明了我的 groupId 和 artifactId?有没有办法强制 Maven 在我的项目目录中使用多个随机的 jar 文件?

感谢您的帮助。

【问题讨论】:

  • 开始使用存储库管理器在此处安装该 jar 文件并使用它作为通常的依赖项...

标签: java maven pom.xml maven-dependency


【解决方案1】:

您还必须在类路径中添加 jar,以便 mvn 获取您的系统依赖项。 &lt;Class-Path&gt;libs/my_file.jar&lt;/Class-Path&gt;

插件配置

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>${maven.jar.plugin.version}</version>
    <configuration>
        <archive>
            <manifestEntries>
                <Build-Jdk>${jdk.version}</Build-Jdk>
                <Implementation-Title>${project.name}</Implementation-Title>
                <Implementation-Version>${project.version}</Implementation-Version>
                <Specification-Title>${project.name} Library</Specification-Title>
                <Specification-Version>${project.version}</Specification-Version>
                <Class-Path>libs/my_file.jar</Class-Path>
            </manifestEntries>
            <manifest>
                <addClasspath>true</addClasspath>
                <mainClass>com.app.MainClass</mainClass>
                <classpathPrefix>libs/</classpathPrefix>
            </manifest>
        </archive>
    </configuration>
</plugin>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-20
    • 2011-09-01
    • 2012-03-30
    • 2014-05-25
    • 2017-12-29
    • 2013-12-15
    • 2018-10-20
    • 1970-01-01
    相关资源
    最近更新 更多