将源附加到Maven中的jar库

时间:2018-11-17 06:19:44

标签: java eclipse maven

我使用自定义库mylib.jar,该库不是随Maven一起构建到Eclipse Maven Java项目的。

<dependencies>
    <dependency>
        <groupId>caen</groupId>
        <artifactId>CAENRFIDLibrary</artifactId>
        <scope>system</scope>
        <version>1.0</version>
        <systemPath>${project.basedir}${file.separator}..${file.separator}mylib.jar</systemPath>
    </dependency>
</dependencies>

但是如何告诉系统Eclipse可以找到当前库的源代码在哪里呢?它可能是通过Maven配置的,还是应该通过Java Source Attachment直接告诉Eclipse?

enter image description here

UPD

将库安装到本地jar存储库:

mvn install:install-file -Dfile="C:\Projects\eclipse_ide_workspace\CAENRFIDLibrary.jar" -DgroupId=caen  -DartifactId=CAENRFIDLibrary -Dversion=1 -Dpackaging=jar

看起来不错的输出:

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ standalone-pom ---
[INFO] Installing C:\Projects\eclipse_ide_workspace\CAENRFIDLibrary.jar to C:\Users\vico\.m2\repository\caen\CAENRFIDLibrary\1\CAENRFIDLibrary-1.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.472 s
[INFO] Finished at: 2018-11-17T11:45:41+02:00
[INFO] ------------------------------------------------------------------------

尝试将其添加到我的项目pom.xml

<dependency>
    <groupId>caen</groupId>
    <artifactId>CAENRFIDLibrary</artifactId>
    <version>1.0</version>
</dependency>       

Eclipse pom.xml编辑器抱怨库

Missing artifact caen:CAENRFIDLibrary:jar:1.0

我做错了什么?

1 个答案:

答案 0 :(得分:0)

最好的选择是将自定义jar安装到本地maven存储库。请参阅以下文档

https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html