将第三方罐装入核心库的最佳实践? [英] Best Practice for including 3rd party jars in a core library?

查看:94
本文介绍了将第三方罐装入核心库的最佳实践?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个核心库,我们将其作为JAR包含在我们所有的Web应用程序中,以最大限度地重用代码。现在我们想通过第三方库(iText)通过这个核心库包含一些功能。

We have a core library that we include as a JAR with all of our web applications to maximize code reuse. Now we'd like to include some functionality through this core library via a 3rd party library (iText).

将iText JAR添加到核心库不起作用,因为类加载器找不到嵌套的JAR。我们不希望将iText JAR添加到每个Web应用程序,因为Web应用程序不使用iText,他们使用的是使用iText的库。语义?也许,但是将第三方JAR添加到Web应用程序中,因此它使用的库可以访问JAR中的类看起来很乱。

Adding the iText JAR to the core library doesn't work because nested JARs aren't found by the classloader. We don't want to add the iText JAR to each Web Application because the web applications aren't using iText, They are using a library that is using iText. Semantics? Perhaps, but adding third party JARs to a Web App so a library it uses can access the classes in the JAR seems messy.

我错过了一个解决这个问题的简单实践或者是jar-merge和自定义类加载器最好的方法?

Am I missing a simple practice that addresses this or are jar-merging and custom class loaders the best approaches?

推荐答案

欢迎来到JAR hell,这是Java开发中一个持续存在的问题, OSGi正在获得动力的一个主要原因。直到最近,凌乱方法一直是行业标准,清洁方法的成本可能远远超过快速和肮脏方法的成本。

Welcome to JAR hell, an ongoing issue in Java development, and one of the main reasons that OSGi is gaining steam. "Messy" approaches have been standard in the industry until only very recently, and the costs of clean approaches may well outweigh the cost of the quick and dirty approach.

但是回答你的问题,大多数应用服务器都有一个地方可以放置可在所有网络应用中访问的JARS。例如,Tomcat具有common / lib目录。你可能想把你的JAR放在那里。

But to answer your question, most app servers have a place where you can put JARS that are accessible across all web apps. Tomcat, for instance, has the common/lib directory. You probably want to put your JAR there.

这篇关于将第三方罐装入核心库的最佳实践?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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