ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/mail/MessagingException

后端 未结 4 909
轮回少年
轮回少年 2020-11-30 07:48

I am getting a strange ClassFormatError when using the javaMail api to send email on my spring mvc web app.

Below is my mail-cfg.xml

<         


        
4条回答
  •  鱼传尺愫
    2020-11-30 08:29

    I too faced the same kind of exception when running junits with jmock and maven:

    Exception in constructor: testDoExecute (java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/servlet/http/Cookie at java.lang.ClassLoader.defineClass1(Native Method)

    It is due to classes your code try to access which are not available in the javaee api jar used in the project because your code compiles against incomplete classes, like the JavaEE6 Api and your Unit tests try to access code thats not there. JUnit will simply fail and mark the test as error, printing something like the above exception.

    It could be solved either by adding javax.servlet jar/dependency or changing javaee jar version shown below:

    
        javax.servlet
        servlet-api
        2.5
    
    
    **OR** 
    
    
        javax.j2ee
        j2ee
        1.4
        provided
    
    

    PS: Please add the jar version compatible with your other existing jars in the project.

提交回复
热议问题