简体   繁体   English

在 Java 中管理部署依赖项

[英]Managing Deployment Dependencies in Java

I am trying to figure out what is the best way to handle dependencies in app servers.我试图找出处理应用服务器中依赖项的最佳方法。 We are considering maven to build the apps, but we found a problem.我们正在考虑使用 maven 来构建应用程序,但我们发现了一个问题。 It appears when we need to update a proprietary shared library that doesn't have version number.This happens once a month and we are using Websphere shared library function in the following way:当我们需要更新没有版本号的专有共享库时出现。这种情况每月发生一次,我们通过以下方式使用 Websphere 共享库功能:

  • For each shared library in Websphere we create an alias without version.对于 Websphere 中的每个共享库,我们创建一个没有版本的别名。 For example: db-component-1.2.1 receives the alias db-component.例如:db-component-1.2.1 接收别名 db-component。 During the first deployment, we associate the app with the required libraries using the aliases.在第一次部署期间,我们使用别名将应用程序与所需的库相关联。 As we ignore the version, all apps must use the same version, creating some restrictions.当我们忽略版本时,所有应用程序必须使用相同的版本,从而产生一些限制。 But when we need to upgrade a shared library, we just upload the new library in WS and then, all apps uses the updated version.但是当我们需要升级共享库时,我们只需在 WS 中上传新库,然后所有应用程序都使用更新版本。

We have more than 70 apps that rely on proprietary shared libraries.我们有 70 多个依赖专有共享库的应用程序。 These libraries change constantly, and this solution makes the management easier.这些库不断变化,这个解决方案使管理更容易。 But it seems a bit odd that the dependencies are changed outside the application's build process.但是在应用程序的构建过程之外更改依赖项似乎有点奇怪。 The dependency control isn't reliable anymore, because the info in app's POM may be false.依赖控制不再可靠,因为应用程序的 POM 中的信息可能是假的。 In addition, all apps must use the same versions.此外,所有应用程序必须使用相同的版本。

I think that a better solution may exist.我认为可能存在更好的解决方案。

We've considered another model.我们已经考虑了另一种模式。 Include the dependencies in every war.在每场战争中包含依赖项。 This allows us to use different versions of libraries in each application without restriction.这使我们可以在每个应用程序中不受限制地使用不同版本的库。 But there is one problem: when a change is made in a proprietary shared library, we need to rebuild and redeploy all apps.但是有一个问题:当在专有共享库中进行更改时,我们需要重建和重新部署所有应用程序。

I have thought about our proprietary shared library being so instable or using a solution that mixes both ideas, but I am not sure how to solve this problem.我曾考虑过我们的专有共享库如此不稳定或使用混合了两种想法的解决方案,但我不确定如何解决这个问题。 OSGI looks like a better way to handle dependencies, but we would have the same problem upgrading many apps. OSGI 看起来是处理依赖关系的更好方法,但我们在升级许多应用程序时会遇到同样的问题。

Should we use WS's shared library function?我们应该使用WS的共享库功能吗? Is there a better way to solve this problem?有没有更好的方法来解决这个问题? Tips are highly appreciated.非常感谢提示。

Thanks谢谢

I'm not sure if I fully understand what you are asking, I first thought that you were unsure how to manage dependencies which are not available in a versioned manner, if so:我不确定我是否完全理解您的要求,我首先认为您不确定如何管理以版本化方式不可用的依赖项,如果是这样:

You already mentioned OSGi, you may want to consider running your own maven repository using Nexus which would allow you to version unversioned jars yourself.您已经提到了 OSGi,您可能需要考虑使用Nexus运行您自己的 Maven 存储库,这将允许您自己对未版本控制的 jar 进行版本控制。

Without wishing to state the obvious, you can't use a specific version of something that doesn't have versions...不想说明显的,你不能使用没有版本的东西的特定版本......

But on re-reading your question it sounds like you may be asking whether its better to have explicit dependencies for each of your application or some shared set of dependencies which are updated on the fly, pushing changes to all of your apps.但是在重新阅读您的问题时,听起来您可能会问,为您的每个应用程序或某些共享的一组动态更新的依赖项设置显式依赖项是否更好,从而将更改推送到您的所有应用程序。 I would say the following:我会说以下几点:

  • You want repeatable builds, which means you need to know when you build an application which version of dependent libraries it used您需要可重复的构建,这意味着您在构建应用程序时需要知道它使用了哪个版本的依赖库
  • You want to ensure that all projects pick up latest version of dependencies when next built您希望确保所有项目在下次构建时都选择最新版本的依赖项

You can use the Maven versions plugin to manage this kind of thing, we have a parent pom defining versions of all libs in the dependencyManagement section and run a script against this every 5 minutes to look for updated dependencies.您可以使用 Maven版本插件来管理这种事情,我们有一个父 pom 定义了dependencyManagement部分中所有库的版本,并每 5 分钟运行一个脚本来查找更新的依赖项。 Whenever the parent pom changes all child pom's are updated and checked into source control, which means that once a new shared lib is released, we will try and build and then unit test all our apps.每当父 pom 更改时,所有子 pom 都会更新并签入源代码管理,这意味着一旦发布了新的共享库,我们将尝试构建,然后对我们所有的应用程序进行单元测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM