java 使用maven连接本地项目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6536751/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 16:15:27  来源:igfitidea点击:

Using maven to connect to a local project

javamaven

提问by User1

I have two projects in eclipse:

我在 Eclipse 中有两个项目:

  1. framework: A general library used in several projects.
  2. client: A project that uses framework.
  1. 框架:在多个项目中使用的通用库。
  2. 客户:一个使用framework.

clientis quite large, possibly larger than frameworkat this point. I am using clientas sort of a test fixture for framework. I want to make a few changes in frameworkand test them in client. Currently, I have to do a full build of framework, install it into a maven repo, and then rebuild client.

client相当大,可能比framework此时更大。我将其client用作framework. 我想frameworkclient. 目前,我所要做的完全构建framework,将它安装到一个maven回购,然后重建client

Is there a way to just have clientpoint to frameworkdirectly on my local disk? Any other hints for developing in such a situation (ie is the a better way)?

有没有办法直接在我的本地磁盘上client指向framework?在这种情况下开发的任何其他提示(即更好的方法)?

采纳答案by marchaos

You can specify dependencies from the local disk using <systemPath> like so:

您可以使用 <systemPath> 从本地磁盘指定依赖项,如下所示:

<dependency>
    <groupId>example.logging</groupId>
     <artifactId>commons-logging</artifactId>
     <version>1.0.0</version>
     <scope>system</scope>
     <systemPath>${project.basedir}/lib/commons-logging.jar</systemPath>
</dependency>

I'm not sure if you can point to a directory that has a pom in it, but at least you don't have to deploy it into maven.

我不确定您是否可以指向一个包含 pom 的目录,但至少您不必将它部署到 maven 中。

回答by Daniel

Running mvn installon Framework will build it and install it in your local Maven repository (that is, the Maven repository on your local disk). When you run your tests in Client, Maven will automatically use the version of Framework in your local repository.

mvn install在 Framework 上运行将构建它并将其安装在您本地的 Maven 存储库(即本地磁盘上的 Maven 存储库)中。当您在 Client 中运行测试时,Maven 将自动使用您本地存储库中的 Framework 版本。

回答by artbristol

The m2eclipse plugin is fairly intelligent about Maven dependencies. If you have the frameworkdependency open as a separate project in Eclipse, I think it should use its code for clientrather than the version in your repository. You might need to tweak your project settings if you're already using m2eclipse and it doesn't do this.

m2eclipse 插件在 Maven 依赖项方面相当智能。如果您framework在 Eclipse中将依赖项作为单独的项目打开,我认为它应该使用其代码client而不是存储库中的版本。如果您已经在使用 m2eclipse 并且它没有这样做,您可能需要调整您的项目设置。