user2316667
user2316667

Reputation: 5634

Importing External JAR to Websphere Liberty? [NoClassDefFoundError]

I want to use this JSON parser in my JAX-RS application that runs on Websphere Liberty.

I have done the following:

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

2) Added C:\javalib to enviroment variable CLASSPATH

3) Added fileset xml to serverl.xml

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

4) Unchecked 'Enable project specific settings' in 'Java Compiler'

5) Cleaned the Project

[EDIT]

I was initially creating a new instance and then I turned it into an @ApplicationScoped bean and injected it. Now I get this error:

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

The first step was enough to get it to compile. Now I'm getting what I learned to be a runtime error. I would appreciate help!

Upvotes: 4

Views: 6104

Answers (1)

Holly Cummins
Holly Cummins

Reputation: 11492

You also need a <classloader> element in your application definition in the server.xml, which references the shared library. For example,

<application id="myapp" name="My App" type="war" location="somewhere.war"> <classloader commonLibraryRef="ExternalLibs" /> </application>

Alternatively, if your application is the only user of the library, you could package it in the WEB-INF/lib folder of your war. (Putting it in WebContent/lib in Eclipse should accomplish this.)

Upvotes: 6

Related Questions