Saturday 8 November 2014

java.lang.UnsupportedClassVersionError: JVMCFRE003 bad major version; class=com/davehay/EmployeeServlet, offset=6


cat /opt/IBM/WebSphere/AppServer/profiles/AppSrv01/logs/AppClusterMember1/SystemOut.log

...
[08/11/14 18:29:20:374 GMT] 00000101 webapp        E com.ibm.ws.webcontainer.webapp.WebApp commonInitializationFinish SRVE0266E: E
rror occured while initializing servlets: {0}
                                 java.lang.UnsupportedClassVersionError: JVMCFRE003 bad major version; class=com/davehay/EmployeeServlet, offset=6

...

Various searches led me to this post: -


which kindly points out the Java major versions: -

<snip>
• Java 1.2 uses major version 46
• Java 1.3 uses major version 47
• Java 1.4 uses major version 48
• Java 5 uses major version 49
• Java 6 uses major version 50
• Java 7 uses major version 51
• Java 8 uses major version 52
</snip>

I had a dig around on my server: -

locate EmployeeServlet.class

/home/wasadmin/java/JDBCTest/WEB-INF/com/davehay/EmployeeServlet.class
/home/wasadmin/java/JDBCTest/WEB-INF/lib/com/davehay/EmployeeServlet.class
/home/wasadmin/java/JDBCTest/src/com/davehay/EmployeeServlet.class
/opt/IBM/WebSphere/AppServer/profiles/AppSrv01/installedApps/PCCell1/JDBCTest_war.ear/JDBCTest.war/WEB-INF/classes/com/davehay/EmployeeServlet.class


The first three hits relate to my manual compilation fest, the fourth is created when I deploy the application: -

AdminApp.install('/home/wasadmin/JDBCTest.war', '[ -nopreCompileJSPs -distributeApp -nouseMetaDataFromBinary -nodeployejb -appname "JDBCTest_war" -createMBeansForResources -noreloadEnabled -nodeployws -validateinstall warn -noprocessEmbeddedConfig -filepermission .*\.dll=755#.*\.so=755#.*\.a=755#.*\.sl=755 -noallowDispatchRemoteInclude -noallowServiceRemoteInclude -asyncRequestDispatchType DISABLED -nouseAutoLink -noenableClientModule -clientMode isolated -novalidateSchema -contextroot / -MapResRefToEJB [[ "JDBCTest.war" "" "JDBCTest.war,WEB-INF/web.xml" jdbc/testDB javax.sql.DataSource jdbc/Sample "" "" "" ]] -MapModulesToServers [[ "JDBCTest.war" "JDBCTest.war,WEB-INF/web.xml" WebSphere:cell=PCCell1,cluster=AppCluster ]] -MapWebModToVH [[ "JDBCTest.war" "JDBCTest.war,WEB-INF/web.xml" default_host ]]]' )

AdminConfig.save() 
AdminNodeManagement.syncActiveNodes() 

so I did some digging using javap: -

javap -verbose -classpath /home/wasadmin/java/JDBCTest/WEB-INF/ com/davehay/EmployeeServlet | grep major

  major version: 50

javap -verbose -classpath /home/wasadmin/java/JDBCTest/WEB-INF/lib/ com/davehay/EmployeeServlet | grep major

  major version: 50

javap -verbose -classpath /home/wasadmin/java/JDBCTest/src/ com/davehay/EmployeeServlet | grep major

  major version: 50

javap -verbose -classpath /opt/IBM/WebSphere/AppServer/profiles/AppSrv01/installedApps/PCCell1/JDBCTest_war.ear/JDBCTest.war/WEB-INF/classes/ com/davehay/EmployeeServlet | grep major

  major version: 51

So, the Java 7 version of the class is somehow being compiled when I deploy the WAR file.

I revisited my packaging ( again, this is what happens when one chooses to create JEE applications by hand, rather than using tools such as Eclipse or Maven !! ), and ended up with this: -

META-INF
META-INF/MANIFEST.MF
WEB-INF
WEB-INF/web.xml
WEB-INF/com
WEB-INF/com/davehay
WEB-INF/com/davehay/EmployeeServlet.class
WEB-INF/ibm-web-ext.xml
WEB-INF/lib
WEB-INF/lib/JDBCTest.jar
WEB-INF/lib/META-INF
WEB-INF/lib/META-INF/MANIFEST.MF
WEB-INF/ibm-web-bnd.xml

and re-created the JAR: -

jar cvf ~/JDBCTest.war .

I redeployed the code, and re-checked the Java version of the class: -

javap -verbose -classpath /opt/IBM/WebSphere/AppServer/profiles/AppSrv01/installedApps/PCCell1/JDBCTest_war.ear/JDBCTest.war/WEB-INF/ com/davehay/EmployeeServlet | grep major

  major version: 50

I started the WAR: -

AdminControl.invoke('WebSphere:name=ApplicationManager,process=AppClusterMember1,platform=proxy,node=Node1,version=8.5.5.2,type=ApplicationManager,mbeanIdentifier=ApplicationManager,cell=PCCell1,spec=1.0', 'startApplication', '[JDBCTest_war]', '[java.lang.String]')

and it now comes up cleanly: -

[08/11/14 19:16:44:023 GMT] 000000fe AdminHelper   A   ADMN1008I: An attempt is made to start the JDBCTest_war application. (User ID = defaultWIMFileBasedRealm/wasadmin)
[08/11/14 19:16:44:051 GMT] 000000fe CompositionUn A   WSVR0190I: Starting composition unit WebSphere:cuname=JDBCTest_war in BLA WebSphere:blaname=JDBCTest_war.
[08/11/14 19:16:44:104 GMT] 000000fe ApplicationMg A   WSVR0200I: Starting application: JDBCTest_war
[08/11/14 19:16:44:104 GMT] 000000fe ApplicationMg A   WSVR0204I: Application: JDBCTest_war  Application build level: Unknown
[08/11/14 19:16:44:287 GMT] 000000fe webapp        I com.ibm.ws.webcontainer.webapp.WebGroupImpl WebGroup SRVE0169I: Loading Web Module: JDBCTest.war.
[08/11/14 19:16:44:320 GMT] 000000fe WASSessionCor I SessionContextRegistry getSessionContext SESN0176I: Will create a new session context for application key default_host/
[08/11/14 19:16:44:362 GMT] 000000fe webcontainer  I com.ibm.ws.webcontainer.VirtualHostImpl addWebApplication SRVE0250I: Web Module null has been bound to default_host[*:9080,*:80,*:9443,*:5060,*:5061,*:443,*:9061,*:9044,*:9062,*:9081,*:9444,*:9045,*:9063,*:9082,*:9445,*:9046].
[08/11/14 19:16:44:399 GMT] 000000fe ApplicationMg A   WSVR0221I: Application started: JDBCTest_war
[08/11/14 19:16:44:400 GMT] 000000fe CompositionUn A   WSVR0191I: Composition unit WebSphere:cuname=JDBCTest_war in BLA WebSphere:blaname=JDBCTest_war started.



No comments:

Visual Studio Code - Wow 🙀

Why did I not know that I can merely hit [cmd] [p]  to bring up a search box allowing me to search my project e.g. a repo cloned from GitHub...