Hosted API Service: NoClassDefFoundError

When using a Hosted API Service, I receive the following error whenever I try to access the org.json library:

{
    "code": 14004,
    "message": "Service invocation failed: weborb.exceptions.ServiceException: java.lang.NoClassDefFoundError: org/json/JSONObjectServiceException"
}

However, using other included libraries does not pose a problem. The org.json library is fairly small and standard, so I’m curious why this one is causing this issue?

Thank you.

Hi Tim,

Please make sure to bundle all the dependencies (except for backendless.jar) into the jar file you deploy.

We’re working on simplifying the deployment process and also will be adding many of the standard utility libraries to avoid this very scenario.

Regards,
Mark

All the dependencies (including org.json) are bundled in the jar. However, I’m still getting the error indicated above.

Here you are.

Also, please check if org.json.JSONObjectServiceException is included in the jar.

The problem is that json-20141113.jar is included as a single file into your jar. The jar you deploy into API Engine must be flattened, that is all dependencies must be expanded within the jar (aka fat jar).

Regards,
Mark

I also can suggest you building your projects with Maven Shade plugin. It creates one jar with all unpacked dependencies.
Please, take a look at my example.

pom.xml.zip (0.93kB)

Fat JAR did the trick. Thanks!