如何告诉Maven包含jar依赖,而不是Eclipse中的子项目源目录? [英] How to tell Maven to include the jar dependency, not the subproject source directory in Eclipse?

查看:110
本文介绍了如何告诉Maven包含jar依赖,而不是Eclipse中的子项目源目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Apache Maven来管理我的Java库(jar)和一些使用这些库的项目。为了方便,我使用 mvn eclipse:eclipse 来生成可以导入Eclipse工作区进行编辑的Eclipse项目文件。

I use Apache Maven to manage my Java libs (jar) and some of projects that use the libs. For convinience, I use mvn eclipse:eclipse to generate Eclipse project files which can be imported into Eclipse workspace for editing.

当我在同一个Eclipse工作区中编辑主项目和Java lib项目时,会出现问题。也就是说, mvn eclipse:eclipse .classpath 文件中包含 src路径依赖关系

Problems arise when I edit the main project and Java lib projects in the same Eclipse workspace. That is, mvn eclipse:eclipse includes src path dependency in .classpath file, not the jar dependency as expected.

说我有一个名为 mylib的Jave lib项目 / code>。相应的jar文件 mylib.jar 已经被部署到由我维护的一个私有的Maven repo。为了在主项目中使用mylib.jar, pom.xml 中包含以下依赖关系。

Say I have a Jave lib project named mylib. The corresponding jar file mylib.jar has been deployed to a private Maven repo maintained by me. In order to use mylib.jar in the main project, the following dependency is included in pom.xml.

<!-- pom.xml for the main project -->
<dependency>
  <groupId>namespace.my</groupId>
  <artifactId>mylib</artifactId>
  <version>[1.0, )</version>
</dependency>

mvn compile mvn test 工作完美,其中 mylib.jar 从我的回购中自动下载。但是,当尝试 mvn eclipse:eclipse 时,我发现生成的 .classpath 文件不包括 mylib.jar 依赖关系。相反,它包括mylib的源文件目录如下。

mvn compile and mvn test work perfect, in which mylib.jar is automatically downloaded from my repo. However, when trying mvn eclipse:eclipse, I find the generated .classpath file doesn't include mylib.jar dependency as expected. Instead, it includes source file directory for mylib as follows.

<!-- .classpath file generated by mvn eclipse:eclipse -->
<classpathentry kind="src" path="/mylib"/>

似乎Maven读取Eclipse的元数据并找到mylib,并且主项目在同一工作空间中共存。因此,maven包含了我的好消息来源。该死的。我怎么能告诉maven忽略本地的项目源,只是包含jar文件?

It seems that Maven reads Eclipse's metadata and finds mylib and the main project coexits in the same workspace. Therefore maven includes the source for my good. Damn. How can I tell maven to ignore the local project source and just include the jar file?

推荐答案

我相信这其实是因为他们在Eclipse中关联项目。所以如果你右键单击你的主项目,然后转到项目引用,你的lib项目应该被勾选。

I believe this is actually because they're related projects in Eclipse. So if you right-click on your main project and go to Project References your lib project should be ticked.

如果运行 mvn eclipse:eclipse ,它将自动为任何子项目(模块)添加项目引用。您可以使用maven eclipse插件的 useProjectReferences 属性进行更改。

If you run mvn eclipse:eclipse it will automatically add project references for any sub-projects (modules). You can change this with the useProjectReferences property of the maven eclipse plugin.

默认为 true ,但


当设置为false时,插件将不会创建子项目,而
使用本地
存储库中的已安装软件包引用这些子项目

When set to false, the plugin will not create sub-projects and instead reference those sub-projects using the installed package in the local repository

要使用该属性在pom.xml中设置属性

To use the property either set the property in your pom.xml

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-eclipse-plugin</artifactId>
            <version>2.9</version>
            <configuration>
                <useProjectReferences>false</useProjectReferences>
            </configuration>
        </plugin>
    <plugins>
<build>

或作为命令行上的财产:

Or as a property on the command line:

mvn eclipse:eclipse -Declipse.useProjectReferences=false

这篇关于如何告诉Maven包含jar依赖,而不是Eclipse中的子项目源目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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