简体   繁体   English

使用 JNDI 查找来检查是否在应用程序服务器中?

[英]Use JNDI lookup to check for being in an application server?

I have a library that can be used both inside an application server like Wildfly, or outside.我有一个库,既可以在 Wildfly 等应用程序服务器内部使用,也可以在外部使用。 It shall behave differently, when running in an Enterprise Java environment and the question is - how can I determine where I'm running, without creating a dependency on any 3rd party library?在 Enterprise Java 环境中运行时,它的行为会有所不同,问题是 - 我如何确定我在哪里运行,而不依赖于任何 3rd 方库?

The idea was to use a simple JNDI lookup, but I wonder what I would look up?这个想法是使用简单的 JNDI 查找,但我想知道我会查找什么?

There are lots of questions here explaining the different JNDI namespaces, but I fail to find a list of actual objects you'd expect to find in the directory.这里有很多问题解释了不同的 JNDI 名称空间,但我找不到您希望在目录中找到的实际对象列表。

So, can anyone point to more specific documentation of stuff to find in the java:global, java:app, or java:jboss namespaces? So, can anyone point to more specific documentation of stuff to find in the java:global, java:app, or java:jboss namespaces? Looking for things that "are always there".寻找“一直存在”的东西。

Can I use this approach, for example to distinguish between Wildfly and Glassfish, and - let's say - find out the version I'm running on?我可以使用这种方法,例如区分 Wildfly 和 Glassfish,并且 - 假设 - 找出我正在运行的版本吗?

Or is there a different approach to determine what kind of context I'm running in?或者是否有不同的方法来确定我正在运行什么样的上下文?

I would instead use the fact that there are a bunch of other classes available to you when you're in a JEE environment.相反,当您在 JEE 环境中时,我会使用许多其他类可供您使用的事实。 For example:例如:

try {
    Class<?> clazz = Class.forName("javax.servlet.http.HttpServlet");
}
catch( ClassNotFoundException classNotFoundException ) {
    // not on an Java EE server       
}

That does not tell you the version or other information about what you're running on.这不会告诉您有关您正在运行的版本或其他信息。 That part usually requires some JMX calls to determine.该部分通常需要一些 JMX 调用来确定。 For example, for Wildfly/JBoss, take a look here for some details.例如,对于 Wildfly/JBoss,请查看此处了解一些详细信息。 Properly written it shouldn't matter for recent versions.正确编写它对最新版本无关紧要。

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

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