3

I have a jar compiled with java 1.6.0_45 but when I try to run this on an AIX machine having java 1.6.0 it gives me the below exception:

2016-08-12 15:32:39,179 WARN o.s.b.SpringApplication [main] Error handling failed (no error message)
2016-08-12 15:32:39,197 INFO o.h.v.i.u.Version [background-preinit] HV000001: Hibernate Validator 5.2.4.Final
2016-08-12 15:32:39,249 ERROR o.s.b.SpringApplication [main] Application startup failed
java.lang.UnsupportedClassVersionError: JVMCFRE003 bad major version; class=javax/annotation/ManagedBean, offset=6
    at java.lang.ClassLoader.defineClass(ClassLoader.java:275) ~[?:1.6.0]
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:69) ~[?:?]
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:529) ~[?:1.6.0]
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:440) ~[?:1.6.0]
    at java.net.URLClassLoader.access$300(URLClassLoader.java:68) ~[?:1.6.0]
    at java.net.URLClassLoader$ClassFinder.run(URLClassLoader.java:1027) ~[?:1.6.0]
    at java.security.AccessController.doPrivileged(AccessController.java:284) ~[?:?]
    at java.net.URLClassLoader.findClass(URLClassLoader.java:418) ~[?:1.6.0]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:660) ~[?:1.6.0]
    at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:89) ~[DiamondFeedGeneratorCMTTool-1.0.jar:?]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:626) ~[?:1.6.0]
    at org.springframework.util.ClassUtils.forName(ClassUtils.java:250) ~[spring-core-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
    at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.registerDefaultFilters(ClassPathScanningCandidateComponentProvider.java:243) ~[spring-context-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
    at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.<init>(ClassPathScanningCandidateComponentProvider.java:116) ~[spring-context-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
    at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.<init>(ClassPathBeanDefinitionScanner.java:136) ~[spring-context-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
    at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.<init>(ClassPathBeanDefinitionScanner.java:111) ~[spring-context-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
    at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.<init>(ClassPathBeanDefinitionScanner.java:83) ~[spring-context-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
    at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:62) ~[spring-context-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
    at java.lang.J9VMInternals.newInstanceImpl(Native Method) ~[?:1.6.0]
    at java.lang.Class.newInstance(Class.java:1345) ~[?:1.6.0]
    at org.springframework.beans.BeanUtils.instantiate(BeanUtils.java:77) ~[spring-beans-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
    at org.springframework.boot.SpringApplication.createApplicationContext(SpringApplication.java:595) [spring-boot-1.4.0.RELEASE.jar!/:1.4.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:310) [spring-boot-1.4.0.RELEASE.jar!/:1.4.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1185) [spring-boot-1.4.0.RELEASE.jar!/:1.4.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1174) [spring-boot-1.4.0.RELEASE.jar!/:1.4.0.RELEASE]
    at com.td.diamond.cmt.feed.generator.config.DiamondFeedGeneratorConfig.main(DiamondFeedGeneratorConfig.java:44) [classes!/:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.6.0]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48) ~[?:1.6.0]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[?:1.6.0]
    at java.lang.reflect.Method.invoke(Method.java:600) ~[?:1.6.0]
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [DiamondFeedGeneratorCMTTool-1.0.jar:?]
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [DiamondFeedGeneratorCMTTool-1.0.jar:?]
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [DiamondFeedGeneratorCMTTool-1.0.jar:?]
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:58) [DiamondFeedGeneratorCMTTool-1.0.jar:?]

Any suggestions what the issue could be and how to fix this?

neo83
  • 29
  • 8
  • 1
    Are you by any chance packaging java ee api jar ? – Nicolas Henneaux Aug 15 '16 at 14:35
  • do you have any code? – Youcef LAIDANI Aug 15 '16 at 14:42
  • @Nicolas It's a spring boot web application. – neo83 Aug 15 '16 at 14:47
  • @Youcef Yes I have. But what specifically are you looking for? – neo83 Aug 15 '16 at 14:47
  • What web container / app server do you use? – Stefan Zobel Aug 15 '16 at 16:06
  • @Stefan - As this is a Spring boot application so it runs on the bundled tomcat and the tomcat version that I have configured is 7.0.59 – neo83 Aug 15 '16 at 17:28
  • @Vineet Ah, ok. I figured it could be Tomcat 8. Then this would have been relevant: http://stackoverflow.com/questions/30235671/spring-boot-java-6-java-lang-unsupportedclassversionerror-x-unsupported-major – Stefan Zobel Aug 15 '16 at 17:41
  • @Stefan I already have this configuration in my pom to use tomcat 7.0.59 and not Tomcat 8. – neo83 Aug 15 '16 at 18:03
  • 1
    @Vineet I understand. Where does the `javax.annotation.ManagedBean` class come from (which jar)? As I read the stacktrace ManagedBean must have been compiled with Java 7 or higher. – Stefan Zobel Aug 15 '16 at 18:07
  • 1
    @Vineet The javax.annotation.Ma‌​nagedBean from `tomcat-embed-core-7.0.59.jar` has been compiled for target 1.6. I'd check that you don't have a second incarnation of j.a.Ma‌​nagedBean on the classpath that was compiled for target > 1.6. – Stefan Zobel Aug 15 '16 at 18:52
  • I couldn't find any other instance of j.a.Ma‌​nagedBean on the classpath. I am going to upgrade the java version to 1.6.0_45 and will check if that resolves the problem. – neo83 Aug 15 '16 at 20:44
  • @Vineet You could try a `Class.forName("javax.annotation.Ma‌​nagedBean")` with your 1.6.0 first. I'd be really baffled if that doesn't work. – Stefan Zobel Aug 15 '16 at 20:54

1 Answers1

0

It is a spring boot application but in your classpath (lib directory of your war for example) a Java EE API jar is present (javaee-api or servlet-api). It does not contain the implementation of the annotation ManagedBean and thus it throws the error.

Usually, this type of library is used for compilation only in an application deployed on server implementing these specifications (Servlet or Java EE).

Nicolas Henneaux
  • 11,507
  • 11
  • 57
  • 82
  • 2
    You might want to provide further clarification that he has included stub 'for compilation only' versions of those libraries, which cannot work at runtime. – Mark Rotteveel Aug 16 '16 at 07:28