您如何使用Maven共享两个项目的源代码? [英] How do you use Maven to share source code for two projects?

查看:202
本文介绍了您如何使用Maven共享两个项目的源代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Maven的大型Java Web应用程序项目,我需要启动一个新项目,该项目将共享大多数相同的代码(因此我不必重复工作),但不是全部.我将把共享代码复制到一个新项目中(我们称之为"root").如何使原始项目依赖于root来获取源代码?我不能只是添加它,因为我想在编译之前更改源代码.

I have a large Java Web Application project using Maven and I need to start a new project that will share most of the same code (so I don't have to repeat work), but not all of it. I'm going to copy the shared code into a new project (let's call it "root"). How do I make my original Project depend on root for source code? I can't just jar it because I want to change the source before compiling.

推荐答案

您应该重构项目.

  1. 识别常用代码
  2. 将其提取到自己的Maven模块中
    2.1.通常,Web应用程序是多模块的,因此,如果要在两个Web应用程序之间共享公共库,则将公共库分成其自己的group-id
  3. 将jar文件构建并安装到您的存储库中
  4. 更改网络应用程序的运行时,以依赖于您的新库
  1. Identify the common code
  2. Extract that into its own maven module
    2.1. usually web-apps are multi module, so if you are going to share the common library across two web-apps, then separate the common library out into its own group-id
  3. Build and install the jar file into your repository
  4. change the poms of the web-apps to depend on your new library

这篇关于您如何使用Maven共享两个项目的源代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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