Maven不会将目标依赖项添加到目标jar [英] Maven won't add local dependency to target jar

查看:138
本文介绍了Maven不会将目标依赖项添加到目标jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个maven项目,除了使用普通的repos之外还使用了一个本地jar。 jar以清单的方式定义:

I have a maven project that besides using normal repos also uses a local jar. The jar is defined in the manifest this way:

    <dependency>
        <groupId>com.mirrorworlds</groupId>
        <artifactId>lstnef</artifactId>
        <version>1.0.0</version>
        <optional>false</optional>
        <scope>system</scope>
        <systemPath>${basedir}/lib/lstnef-1.0.0.jar</systemPath>
    </dependency>

安装脚本成功运行,但应用程序启动后我得到了:

The install script works successfully, but after the app is launched I get this:

Exception in thread "main" java.lang.NoClassDefFoundError: 
com/mirrorworlds/lifestreams/mail/tnef/internet/TnefMultipart 
at ...processMails(MailProcessor.java:57)
at ...main(MailReader.java:42)

当我查看目标jar时,我也找不到这些类,尽管它们应该在 lstnef-1.0.0.jar

When I look inside the target jar I can't find these classes as well, though they are supposed to be inside lstnef-1.0.0.jar

我会感谢任何解决这个谜团的建议。

I'll be thankful for any suggestions on solving this mystery.

推荐答案

我使用的可能解决方案是在编译阶段之前将此系统JAR安装到本地Maven存储库中,然后将此JAR作为Maven工件引用。即。

Possible solution I use is installing this system JAR into the local Maven repository before compilation phase and then reference this JAR as a Maven artifact. I.e.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-install-plugin</artifactId>
    <version>2.2</version>
    <executions>
        <execution>
            <id>your-file</id>
            <inherited>false</inherited>
            <phase>validate</phase>
            <configuration>
                <file>${pom.basedir}/lib/your-file-4.8.jar</file>
                <repositoryLayout>default</repositoryLayout>
                <groupId>your-file</groupId>
                <artifactId>your-file</artifactId>
                <version>4.8</version>
                <packaging>jar</packaging>
                <generatePom>true</generatePom>
            </configuration>
            <goals>
                <goal>install-file</goal>
            </goals>
        </execution>
    </executions>
</plugin>

然后引用它:

<dependency>
    <groupId>your-file</groupId>
    <artifactId>your-file</artifactId>
    <version>4.8</version>    
</dependency>

这篇关于Maven不会将目标依赖项添加到目标jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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