1

I am try to send a text message via a Java Code following Twilio tutorial here but i am getting java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/JsonMappingException at Line 13 in my code where i am writing Service service = Service.creator("My First Messaging Service").create();

I tried following this thread and have added all the required dependencies but i don't know where to use @JsonIgnore in my code Caused by: java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/JsonMappingException$Reference

How can i resolve this? Please help me how to fix this. Here's my java code

import com.twilio.Twilio;
import com.twilio.rest.messaging.v1.Service;
import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.core.*;
public class SMSOTP 
{
    public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID");
    public static final String AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN");
    public static void main(String[] args) 
    {
        Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
        Service service = Service.creator("My First Messaging Service").create();

        System.out.println(service.getSid());
    }
}
  • https://findjar.com/class/com/fasterxml/jackson/databind/JsonMappingException.html – fantaghirocco Nov 20 '20 at 14:56
  • @fantaghirocco : Thank you for your reply. I already have jackson-databind-2.11.3.jar file from mvnrepository, can you please tell which one should i download ? – Guriqbal Singh Nov 20 '20 at 15:12
  • 1
    You should not download `jar` files manually. Try to setup `Maven` or `Gradle` to build project and it should work. Take a look at: [Adding dependencies in build.gradle](https://www.twilio.com/docs/sms/quickstart/java#adding-dependencies-in-buildgradle) and [Using with a build automation tool](https://www.twilio.com/docs/libraries/java#using-with-a-build-automation-tool) – Michał Ziober Nov 20 '20 at 17:41
  • 1
    @MichałZiober : Hi Michal. Thank you for your suggestion. I am used to Maven already but yeah not doing that here in this project, but still using maven i need to specify the version in pom.xml file. So i am just asking which one should i switch to? Because currently i am already having latest stable versions. – Guriqbal Singh Nov 20 '20 at 18:47
  • 1
    @MichałZiober : Hi Michal. I took your suggestion seriously and switched to Maven and tadaa :P It is working now :)))) Thanks a lot man! – Guriqbal Singh Nov 20 '20 at 20:04

1 Answers1

1

To anyone who came here looking for a solution, it is seriously a dependency problem. I had 3 jackson APIs' (annotations, databind and core) added manually to my project and that was the issue. It actually required more then that.

So what i did is switched to Maven project by following Convert Existing Eclipse Project to Maven Project and in pom.xml, in <builds> i copy pasted all the <plugins> that twilio required to work from here https://github.com/twilio/twilio-java/blob/main/pom.xml

Thanks to @MichałZiober for the suggestion, it eventually worked.

Hope this helps anyone from scratching their heads for hours :) Goodluck!