sun.reflect.annotation.TypeNotPresentExceptionProxy error when deploy web-ear

后端 未结 7 503
说谎
说谎 2020-12-17 07:20

When I try to deploy ejd-ear, web-ear on to glassfish server. I added an ejb client dependency in web project. The ejb-ear deploys successfully. But when I try to deploy web

相关标签:
7条回答
  • 2020-12-17 08:12

    Solution:

    1. Connect with debug to Glassfish server
    2. Put break point into line
      • java.lang.Class.initAnnotationsIfNecessary(Class.java:3070)
    3. Deploy your application.

    While deploying you will stop several times at this break point. See this reference and remember the last before deployment error arise. Than check Annotations in last "this" class. You can also put break point into AnnotationParser.parseClassArray method, but it is compiled code and break point on the method is very slow. (In my case with method break point I could not depoy application at last).

    0 讨论(0)
  • 2020-12-17 08:14

    This can also happen in the following situation:

    project A is some library, a maven project in your eclipse. It has a class named org.exmaple.Foo which is in the src/test/java/ directory.

    in your project B where the error occurs you are try to access this class. But this isn't possible.

    Eclipse won't complain because it "knows" both classes. If you are running mvn clean install on the project that does not work maven will give you a proper error message.

    I think this erro can occur since Kepler but I am not sure. At least it is still present in Luna :)

    0 讨论(0)
  • 2020-12-17 08:16

    I think the best way is to put a break point in the constructor of java.lang.TypeNotPresentException and check the second argument of type Throwable to know the root cause

    0 讨论(0)
  • 2020-12-17 08:17

    Had the same exception recently with JUnit. The situation was like this:

    @SuiteClasses({MyTestClass.class})
    public class MySuite {
        ...
    }
    

    Problem is that JVM was unable to process MyTestClass because it was missing dependencies in the classpath (another JAR file was missing). But the exception provided no information on which class was missing.

    Solution was to temporarily add a static initialization block to MySuite, that instantiates MyTestClass:

    @SuiteClasses({MyTestClass.class})
    public class MySuite {
        static {
            new MyTestClass();
        }
    }
    

    this causes JVM to run the static block first, try to instantiate MyTestClass, find out the missing class and report a proper exception. Then you can add the missing dependency and remove the temporary static block.

    0 讨论(0)
  • 2020-12-17 08:20

    The issue is conflicting with Jar file. Verify the list of jar files inside war file lib folder. Remove unnecessary and conflicting jar files. Then the deployment will be successful.

    0 讨论(0)
  • 2020-12-17 08:21

    TypeNotPresentExceptionProxy error is not specific to a particular dependency and depends on each project's classpath. So verify your maven dependencies tree. For example, I fell into this error one time when I had two dependencies of JUnit so there were two versions of JUnit annotations in the classpath.

    You can put a breakpoint in some of the methods of class "java.lang.Class":

    For example:

    java.lang.Class.getAnnotation 
    java.lang.Class.getAnnotations 
    

    After that, you will be able to discover which class cause the problem... search inside the class for annotations and check your classpath for ambiguities.

    0 讨论(0)
提交回复
热议问题