如何将源代码添加到 Maven 中的依赖库中?
例如,我已将 junit-addons 包含在我的依赖项中:junit-addons。但是在maven仓库中没有任何源代码。我知道它存在(我已经下载了)。如何修改依赖项以便使用本地项目中的库而不是 Maven 存储库中的库(我会省略存储库中的 junit-addons 并使用本地 JAR 及其源代码)。
注意:我使用m2eclipse。
For instance, I have included into my dependencies junit-addons : junit-addons. But in the maven repository there isn't any source code. And I know it exists (I have downloaded it). How can I modify the dependencies in order to use libraries from my local project instead from the maven repository (I would omit the junit-addons from the respository and use a local JAR and its source code instead).
Note: I use m2eclipse.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我以非常直接的方式解决了问题:
我已复制到文件夹
${user.home}/.m2/repository/{group-name}/{artifactId}/{version}/ 遵循 MAVEN 标准的源文件:
{artifactId}-{version}-sources.jar
它就像一个魅力! Eclipse 检查本地存储库并找到源。不过,我不知道这是否是 MAVEN 的方式。
I've solved the problem in a very straight forward way:
I have copied into the folder
${user.home}/.m2/repository/{group-name}/{artifactId}/{version}/
the source file following MAVEN standard:{artifactId}-{version}-sources.jar
and it works as a charm! Eclipse checks the local repository and finds the sources.I don't know if this is the MAVEN way, though.
您不能。如果中央存储库中没有可用的源 JAR,只需将源放在文件系统上的某个文件夹、JAR 或 zip 中(您可以
install:install-file
将源存档放在本地存储库,遵循 Maven 的约定)并设置 Eclipse 以使用它们(右键单击Package Explorer 中 Maven Dependencies 下的 JAR,选择 Java Source Attachment并设置位置路径)。You can't. If a sources JAR isn't available in the central repository, just put the sources somewhere on your file system in a folder, JAR or zip (you could
install:install-file
a sources archive in your local repository, following Maven's conventions) and setup Eclipse to use them (right-click on the JAR under Maven Dependencies in the Package Explorer, select Java Source Attachment and setup the Location path).我使用免费版本的 Artifactory 存储库。我创建了一个 jar 文件 {artifactId}-{version}-sources.jar 并将其上传到存储库,并与二进制 jar 文件具有相同的组 ID。
然后在我的 pom 中添加了依赖项:
在 Maven 构建阶段,源 jar 被下载到我的本地存储库。
我使用 netbeans 7.0,它会自动为我管理一切。例如,右键单击方法并选择 go toSource 正确地将我带到 jar 中的源代码。
I use free version of Artifactory repository. I created a jar file {artifactId}-{version}-sources.jar and uploaded to the repository into the same group-id as binary jar file.
Then in my pom I added dependency:
During maven build phase source jar was downloaded to my local repository.
I use netbeans 7.0 and it automatically managed everything for me. For example, right click on method and choosing go toSource correctly brings me to source code in the jar.
将其下载到本地存储库后,您可以复制它。给它一个新的artifactId(例如libraryName-myVersion)并在pom.xml中添加依赖项。确保更改了 pom.xml 中的文件夹名称、jar 名称、pom 名称和 artifactId 本身。将所有内容存储在本地存储库中。现在您可以使用您的依赖项的破解版本。
但说实话,我不认为这是一个好主意。但也许它对你的情况有帮助/无法避免。
After you have downloaded it into your local repository, you could make a copy of it. Give it a new artifactId (e.g. libraryName-myVersion) and add dependencies in the pom. Make sure you change the folder names, jar names, pom names and the artifactId itself in the pom. Store everything in your local repository. Now you can use your hacked version of your dependency.
But to be honest, I do not thing this is a good idea to do. But maybe it helps/could not be avoided in your case.
您可以使用 安装文件 mojo将工件本地安装到本地 Maven 存储库中。如果您想与其他人(例如您的团队或其他工作站)共享此工件,您可以使用自己的存储库管理器(例如 Nexus)并将其配置为任何存储库(例如中央存储库)的镜像。 Nexus 将从中央获取(并缓存)工件。此外,您可以将任何工件(例如 junit-addons 源)上传到您的 Nexus 安装中。
为了配置镜像,您必须编辑
${user.home}/.m2/settings.xml
You could use the install-file mojo to locally install artifacts into your local maven repository. If you want to share this artifact with others (say your team or another workstation), you could use your own repository manager (e.g. Nexus) and configure it as a mirror for any repository, e.g. central. Nexus will fetch (and cache) artifacts from central. Additionally, you may upload just about any artifact (like junit-addons sources) to your nexus installation.
In order to do configure a mirror, you'll have to edit
${user.home}/.m2/settings.xml