java.lang.NoClassDefFoundError: com / quickxml / jackson / databind / JsonMappingException

Nov 20 2020

Tôi đang cố gửi tin nhắn văn bản qua Mã Java theo hướng dẫn của Twilio ở đây nhưng tôi đang viết java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/JsonMappingExceptionDòng 13 trong mã của mình, nơi tôi đang viếtService service = Service.creator("My First Messaging Service").create();

Tôi đã thử làm theo chủ đề này và đã thêm tất cả các phụ thuộc bắt buộc nhưng tôi không biết sử dụng @JsonIgnore ở đâu trong mã của mình Nguyên nhân do: java.lang.NoClassDefFoundError: com / quickxml / jackson / databind / JsonMappingException $ Tham khảo

Làm thế nào tôi có thể giải quyết điều này? Xin hãy giúp tôi cách sửa lỗi này. Đây là mã java của tôi

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());
    }
}

Trả lời

1 GuriqbalSingh Nov 21 2020 at 03:17

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!