我想在我在 Websphere Liberty 上运行的 JAX-RS 应用程序中使用这个 JSON parser

我做了以下工作:

1)右键Project -> Properties -> Java Build Path -> Add External Jar -> C:\javalib\quick-json.jar

2) 将 C:\javalib 添加到环境变量 CLASSPATH

3) 将文件集 xml 添加到 serverl.xml

<library id="ExternalLibs">
    <fileset dir="C:\javalib" includes="*.jar"/>
</library>

4) 在“Java Compiler”中取消选中“Enable project specific settings”

5)清理项目

[编辑]

我最初创建了一个新实例,然后将其转换为 @ApplicationScoped bean 并注入(inject)它。现在我收到这个错误:
The JNDI lookup failed for JNDI name java:module/ConsoleREST with the following Exception CNTR4007E: An error occurred creating the websphere.jaxrs.service.ConsoleREST interface for the ConsoleREST enterprise bean in the WebApiConsole.war module in the WebApiConsole application. The enterprise bean look up failed using the java:module/ConsoleREST JNDI name. Exception: com/json/parsers/JsonParserFactory.
CNTR4007E: An error occurred creating the websphere.jaxrs.service.ConsoleREST interface for the ConsoleREST enterprise bean in the WebApiConsole.war module in the WebApiConsole application. The enterprise bean look up failed using the java:module/ConsoleREST JNDI name. Exception: com/json/parsers/JsonParserFactory

第一步足以让它编译。现在我得到了我所学到的运行时错误。我将不胜感激!

最佳答案

您还需要在 server.xml 中的应用程序定义中使用 <classloader> 元素,该元素引用共享库。例如,
<application id="myapp" name="My App" type="war" location="somewhere.war"> <classloader commonLibraryRef="ExternalLibs" /></application>
或者,如果您的应用程序是该库的唯一用户,您可以将其打包在您的 war 的 WEB-INF/lib 文件夹中。 (将它放在 Eclipse 中的 WebContent/lib 中应该可以完成此操作。)

关于eclipse - 将外部 JAR 导入 Websphere Liberty? [NoClassDefFoundError],我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24292443/

10-10 19:49