0

I am developing a spring boot 1.4.2 application on STS to be deployed on weblogic 10 (j2ee 5 , j-se 6) , when trying to run the application as Spring boot application I get this error :

java.lang.UnsupportedClassVersionError: javax/annotation/ManagedBean : Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method) ~[na:1.6.0_45]
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631) ~[na:1.6.0_45]
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615) ~[na:1.6.0_45]
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141) ~[na:1.6.0_45]
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:283) ~[na:1.6.0_45]
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58) ~[na:1.6.0_45]
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197) ~[na:1.6.0_45]
    at java.security.AccessController.doPrivileged(Native Method) ~[na:1.6.0_45]
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190) ~[na:1.6.0_45]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306) ~[na:1.6.0_45]
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) ~[na:1.6.0_45]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247) ~[na:1.6.0_45]
    at org.springframework.util.ClassUtils.forName(ClassUtils.java:250) ~[spring-core-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.registerDefaultFilters(ClassPathScanningCandidateComponentProvider.java:243) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.<init>(ClassPathScanningCandidateComponentProvider.java:116) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.<init>(ClassPathBeanDefinitionScanner.java:136) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.<init>(ClassPathBeanDefinitionScanner.java:111) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.<init>(ClassPathBeanDefinitionScanner.java:83) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext.<init>(AnnotationConfigEmbeddedWebApplicationContext.java:67) ~[spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.6.0_45]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) ~[na:1.6.0_45]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) ~[na:1.6.0_45]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513) ~[na:1.6.0_45]
    at java.lang.Class.newInstance0(Class.java:357) ~[na:1.6.0_45]
    at java.lang.Class.newInstance(Class.java:310) ~[na:1.6.0_45]
    at org.springframework.beans.BeanUtils.instantiate(BeanUtils.java:77) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.boot.SpringApplication.createApplicationContext(SpringApplication.java:597) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:311) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
    at com.ejada.staripo.OnlineChannelBackendApplication.main(OnlineChannelBackendApplication.java:22) [main/:na]

I know the cause of the error (old version at compilation, new version at runtime) ... what I am not able to figure out is what causes the error ...I should be compiling my application with java 6 ... but the error says that something is compiled using java 7

gradle guild file :

buildscript {
    ext {
        springBootVersion = '1.4.2.RELEASE'
    }
    repositories {
        mavenCentral()
        mavenLocal()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'

group = 'com.mypack'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.6 //java6

repositories {
    mavenCentral()
    mavenLocal()
}

configurations {
    providedRuntime
    //jaxb
}

// tag::wsdl[]
//  task genJaxb {
//      ext.sourcesDir = "${projectDir}/src/main/java"
//      ext.classesDir = "${buildDir}/classes/jaxb"
//      ext.schema1 = "src/main/resources/com/ejada/staripo/wsdl/ELMCitizenInfoInq.wsdl"
//      ext.src1 = "${projectDir}/src/main/java/com/ejada/staripo/backend/elm/citizeninfo"
//      ext.schema2 = "src/main/resources/com/ejada/staripo/wsdl/ELMMuqeemInfoInq.wsdl"
//      ext.src2 = "${projectDir}/src/main/java/com/ejada/staripo/backend/elm/muqeeminfo"
//
//      outputs.dir classesDir
//
//      doLast() {
//          project.ant {
//              taskdef name: "xjc", classname: "com.sun.tools.xjc.XJCTask",
//                      classpath: configurations.jaxb.asPath
//              mkdir(dir: sourcesDir)
//              mkdir(dir: classesDir)
//
//              xjc(destdir: sourcesDir, schema: schema1,
//                      package: "com.ejada.staripo.backend.elm.citizeninfo") {
//                  arg(value: "-wsdl")
//                  produces(dir: sourcesDir, includes: "**/*.java")
//              }
//
//              xjc(destdir: sourcesDir, schema: schema2,
//                      package: "com.ejada.staripo.backend.elm.muqeeminfo") {
//                  arg(value: "-wsdl")
//                  produces(dir: sourcesDir, includes: "**/*.java")
//              }
//
//
//              javac(destdir: classesDir, source: 1.8, target: 1.8, debug: true,
//                      debugLevel: "lines,vars,source",
//                      classpath: configurations.jaxb.asPath) {
//                  src(path: src1)
//                  include(name: "**/*.java")
//                  include(name: "*.java")
//              }
//
//              copy(todir: classesDir) {
//                  fileset(dir: src1, erroronmissingdir: false) {
//                      exclude(name: "**/*.java")
//                  }
//              }
//              
//                          javac(destdir: classesDir, source: 1.8, target: 1.8, debug: true,
//                      debugLevel: "lines,vars,source",
//                      classpath: configurations.jaxb.asPath) {
//                  src(path: src2)
//                  include(name: "**/*.java")
//                  include(name: "*.java")
//              }
//
//              copy(todir: classesDir) {
//                  fileset(dir: src2, erroronmissingdir: false) {
//                      exclude(name: "**/*.java")
//                  }
//              }
//          }
//      }
//  }
// end::wsdl[]

dependencies {
    compile('org.springframework.boot:spring-boot-legacy:1.1.0.RELEASE')
    compile('org.springframework.boot:spring-boot-starter-web:1.4.2.RELEASE')
    compile('com.fasterxml.jackson.core:jackson-databind:2.6.7') //java6
    compile('org.springframework.ws:spring-ws-core')
    compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:1.2.0')
    compile('org.projectlombok:lombok:1.16.10')
    compile('com.oracle:ojdbc6:11.1.0.7.0') //java6
    //compileOnly('org.springframework.boot:spring-boot-devtools')
    compileOnly('javax.servlet:servlet-api:2.5')
    //compile(files(genJaxb.classesDir).builtBy(genJaxb))

    //jaxb "com.sun.xml.bind:jaxb-xjc:2.1.7"
    providedRuntime('org.springframework.boot:spring-boot-starter-tomcat') // commented for java6
    providedRuntime('org.apache.tomcat:tomcat-juli:7.0.59') // java6
    //compileOnly group:'org.apache.tomcat', name:'tomcat-juli', version:'7.0.59' // java6
    testCompile('org.springframework.boot:spring-boot-starter-test')
    //testCompile('org.springframework.security:spring-security-test')
}

    /*compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-data-rest')
    compile('org.springframework.boot:spring-boot-starter-security')
    compile('org.springframework.session:spring-session-core')
    */

//bootJar { //commented 4 java6
  //  baseName = 'gs-consuming-web-service'
    //version =  '0.1.0'

  //  from genJaxb.classesDir
//}


//task afterEclipseImport {
  //  dependsOn genJaxb
//}

and here is the lib folder in the generated war :

enter image description here

Stephane Nicoll
  • 31,977
  • 9
  • 97
  • 89
osama yaccoub
  • 1,884
  • 2
  • 17
  • 47

3 Answers3

1

What I did is that I generated a war and deployed it to external tonmcat 7 instead of the embedded one .... the error there was clearer for some reason which I don't know ... It pointed directly to the package which was causing the error , it was in spring-ws-core hence I needed to use version 2.2.4.RELEASE

osama yaccoub
  • 1,884
  • 2
  • 17
  • 47
1

You need to set the tomcat version to 7 in your build script for Java 6. You can find some additional configuration in Spring Boot document. https://docs.spring.io/spring-boot/docs/1.4.4.RELEASE/reference/htmlsingle/#howto-use-java-6

For example: Gradle script

ext['tomcat.version'] = '7.0.59'

I hope this help.

Jun Ee
  • 301
  • 2
  • 4
0

Firstly, sourceCompatibility only specifies the source compatibility of your code. To generate .class files of the desired version, you should use targetCompatibility. See this answer.

Secondly, the cause of your error:

java.lang.UnsupportedClassVersionError: javax/annotation/ManagedBean : Unsupported major.minor version 51.0

Is not:

old version at compilation, new version at runtime

But: New vesion at compilation, old version of jvm

Thirdly, the javax.annotation.ManagedBean is not compiled from your sources, but is a part of the Javax Annotation API, you should choose a java-6-compatible jar.

std4453
  • 528
  • 7
  • 12
  • thanks for the first note, it's useful but I think it's not sufficient, it didn't fix actually... for the seond it was just a typo from my side :) .. for the third can you please clarify more ... what jar exactly shall I choose an alternative version for ? – osama yaccoub Apr 22 '18 at 16:16