Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bluemix Java Liberty Web Project java.lang.NoClassDefFoundError: when loading third party jar

Im using IBM Bluemix's Java For Liberty to deploying a web app.

I was trying to get the system env and converted it to JSONObject

enter image description here

And I pretty sure Ive added the jar file to the classpath

enter image description here

However, after I ran the app(tried push to bluemix cloud and running locally in a liberty profile app server), it throws java.lang.NoClassDefFoundError

enter image description here

please indicate how should I configure.....

like image 666
Qing Avatar asked Dec 04 '25 04:12

Qing


2 Answers

The jars in the dep-jar folder do NOT get packaged with the final application binary(war). It is meant to be used during compilation only. If you want the jar to be included in the war (use during runtime), you need to include it in WebContent/WEB-INF/lib folder.

If you create and download the Java DB Web Starter boilerplate, you will see the right structure set up - WebContent/WEB-INF/lib/nosqljson.jar

like image 69
Ram Vennam Avatar answered Dec 06 '25 22:12

Ram Vennam


You need to add your jar's to the dep-jar folder and build the war file with the included build.xml.

Look for classPathDir in build.xml, it will look like the following.

<path id="classpathDir">
        <pathelement location="bin"/>
        <pathelement location="dep-jar/com.ibm.ws.javaee.jaxrs.1.1_1.0.1.jar"/>
    </path>

You will need to add each of your jar's to that block. For example.

    <path id="classpathDir">
        <pathelement location="bin"/>
        <pathelement location="dep-jar/com.ibm.ws.javaee.jaxrs.1.1_1.0.1.jar"/>
        <pathelement location="dep-jar/json-1.0.0.jar"/>
    </path>

Or you could do the following which would include all jar's in dep-jar.

<path id="classpathDir">
    <pathelement location="bin"/>
    <pathelement location="dep-jar/com.ibm.ws.javaee.jaxrs.1.1_1.0.1.jar"/>
    <fileset dir="dep-jar/" includes="*.jar" />
</path>
like image 45
Jeff Sloyer Avatar answered Dec 06 '25 21:12

Jeff Sloyer