Libraries and Business Logic

Every time I try to use a 3rd-party library in my business logic, I get this error:

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/gson/JsonObject

I’ve even tried using alternative libraries, but they return the same error. Whether I deploy the code or run it on CodeRunner.
I’ve added the library’s JAR to the project’s libs folder. Is there something else I am forgetting to do?

Hi.
Try to archive all your libs and third party libs in one zip archive (without any folders/subfolders).

Okay, I’ve archived but where exactly in my project structure do I import them?

Using IntelliJ idea and currently my libs all reside in the libs folder.

Also, this question was not solved* but it is marked as solved? I have beens struggling to successfully use 3rd-party libraries with Business Logic for weeks now.

From everything I’ve read / found, having the JAR in my libs folder (as pictured) is supposed to suffice. But clearly it is not being imported properly as when I run it via CodeRunner it says the files can’t be found.

http://support.backendless.com/public/attachments/929b4b06aff0767899fa17bd373d33cf.png</img>

929b4b06aff0767899fa17bd373d33cf.png

Could you clarify, how are you deploying your code and what logic do you use (handlers, timer, services).

Any help? I have been blocked by this for a while now…

Please respond to Oleg’s question here:

http://support.backendless.com/t/libraries-and-business-logic#comment-17535

I am running my Business Logic via CodeRunner. It is a timer that runs every 60 seconds.

Within the timer I access JSON data from an API

I put together a sample timer which uses the gson-2.5.jar library. I had no problem deploying that code. Here’s a link to the complete project - you just need to add your app id and secret key. Please give it a try and let me know if it works:

Mark

i have this problem also
i can not add 3d party library to my bussiness logic code
i see noclassdeffound error when run api

i confused with add library to service api
i see this error:
what i do know?i need add 3d party library to service api

{
“code”: 0,
“message”: “Type:“java.lang.NoClassDefFoundError”, Description:“com/squareup/moshi/Moshi$Builder”\nExceptionClass:“ServiceException” {Msg:“none”, Cause:“none”}”
}

Hamid,
Please take a look at this comment, where Mark, points to an example of a custom business logic project which uses third party libraries

You can download it, try if it works for you and add your own third-party libraries in the same way