找不到类型为 'library'、ID 为 'some-id' 的元素

An element of type 'library' with ID 'some-id' could not be found

我想从我的程序中获取一些属性,我必须使用 JNDI 来完成(一些属性是我在那里设置的),使用 WAS Liberty。但是当我使用这些标签时:

<jndiObjectFactory id="id-factory" className="some-class" objectClassName="another-class" libraryRef="name-of-lib" />

server.xml 上,Eclipse 向我显示一条警告:

An element of type 'library' with ID 'name-of-lib' could not be found

我得到这些 类(some-classanother-class),在 pom.xml 上有一个 dependency

我进入了这些 类,但没有找到 name-of-lib

还有另一种方法可以确定 name-of-lib 是否真的在这些 类 中?

您需要在您的 server.xml 中配置一个 <library> 元素,给它一个 ID,并使您的 <library> 的 ID 成为 libraryRef.

假设您的文件系统 /temp/myLibs/foo.jar 中有库 foo.jar,您可以在 server.xml 中配置此库,如下所示:

<jndiObjectFactory ... libraryRef="MyLib"/>

<library id="MyLib">
  <fileset dir="/temp/myLibs" includes="*.jar"/>
</library>

或者不使用 libraryRef 指向您的 <library> 的 ID,您可以将 <library> 嵌套在您的 <jndiObjectFactory> 下,如下所示:

<jndiObjectFactory ...>
  <library>
    <fileset dir="/temp/myLibs" includes="*.jar"/>
  </library>
</jndiObjectFactory>

这里是 IBM Doc for shared library configuration.