我是否可以在独立 ejb 模块中引用任何外部第 3 方 jar?

发布于 2024-09-03 15:18:07 字数 150 浏览 2 评论 0 原文

我们是否可以永远在独立的 ejb 模块中引用任何外部第 3 方 jar(除了在我们的 appserver/lib 中复制 jar 文件)?这看起来很不合逻辑不是吗?我不想创建企业应用程序。如果我必须使用任何 jar 文件,为什么我被迫创建企业应用程序?

没有其他选择吗?

Can we never refer any external 3rd party jar in independent ejb module (except copying the jar file in our appserver/lib)? This seems so illogical doesn't it? I don't want to create a Enterprise application. Why am i being forced to create an Enterprise application if i have to use any jar files?

Are there no alternatives available?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一场信仰旅途 2024-09-10 15:18:07

好吧,我想我在我的 之前的回答

EJB 没有相当于 WEB-INF/lib 的文件,虽然 EJB-JAR 内的打包库可能适用于某些应用程序服务器,但这不是 JAR 规范1 并且不符合 Sun 关于 J2EE 打包

我不知道要添加什么,如果你想编写可移植的应用程序,你必须遵守规则。是否由于技术限制(见脚注),这不是问题,规则就是规则。

另一种方法是将库解压到 EJB-JAR 中,这非常难看(在我看来,将库复制到应用程序服务器类路径中并不是可移植应用程序的替代方案)。

话虽这么说,如果您使用的是 Java EE 6,您现在可以 使用 WAR而不是 EAR

1中所述此线程jar 规范不支持 jar 文件中的 jar 文件(从技术上讲,Java 的 URL 支持仅深入一层:例如 jar:url/to/file!path/ in/jar 是允许的,但是jar:jar:url/to/file!path/in/jar!path/in/jar 不是),因此虽然您可以将 jar 文件复制到 ejb jar 中,但不会从中加载任何内容。

Well, I think I gave you a pretty good explanation in my previous answer:

EJBs don't have an equivalent of WEB-INF/lib and while packaging libraries inside an EJB-JAR might work with some application server, this is not part of the JAR specification1 and does not comply with Sun's standards regarding J2EE packaging.

I don't know what to add, if you want to write portable applications, you have to follow the rules. Whether they are due to technical limitations (see footnote), that's not the question, rules are rules.

The alternative would be to unpack the library in your EJB-JAR and that's incredibly ugly (copying your library in the application server classpath is IMO not an alternative for portable applications).

That being said, if you are using Java EE 6, you can now use a WAR instead of an EAR.

1 As explained in this thread, the jar spec does not support jar files within jar files (technically Java's URL support only goes one level deep: eg jar:url/to/file!path/ in/jar is allowed, but jar:jar:url/to/file!path/in/jar!path/in/jar is not) so while you could copy the jar files inside your ejb jar, nothing will be loaded from it.

音盲 2024-09-10 15:18:07

您已经选择了答案,但我会提到“安装的可选软件包”可能会提供解决方案,具体取决于您的服务器中可用的功能。

You've already selected an answer, but I'll mention that "installed optional packages" might offer a solution, depending on the features available in your server.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文