Java version in spring boot , docker and EC2 - java

Spring boot version - 2.1.13.BUILD-SNAPSHOT
Java compiler version - Jdk11
AWS EC2 Java version - jdk7
I've started working on a microservice project. So the docker image of my service was compiled in Jdk11. When I try to download and run the container - it doesn't run. Now upon checking logs, I see - java.lang.UnsupportedClassVersionError
I'm using maven to build. Should I change the java version in pom.xml? I could not update the java version in the ec2. Please let me know how I can resolve this collision and go-ahead. I have many services and I'm trying to put it all in EC2.
Docker file: updated to Java 11
FROM openjdk:11.0-jdk-slim
VOLUME /tmp
COPY snapAppKey.jks snapAppKey.jks
COPY /target/SnapAppConfigServer-0.0.1-SNAPSHOT.jar ConfigServer.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","ConfigServer.jar"]
EC2
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/snapapp/config/api/SnapAppConfigServerApplication has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:93)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:46)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:51)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52)

Migrating your existing code from JDK11 to JDK8 will be more effort that the above simple operations.
change openjdk:8-jdk-alpine to openjdk:11 in your Docker file

Related

Unsupported ClassVersion Error when deploying jira

I am trying to run jira application on my local machine with atlas-run and atlas-debug command. But i have a build failure here.
[ERROR] Failed to execute goal com.atlassian.maven.plugins:maven-amps-dispatcher-plugin:6.2.1:run (default-cli) on project ccd_jirautils: Execution de
fault-cli of goal com.atlassian.maven.plugins:maven-amps-dispatcher-plugin:6.2.1:run failed: Unable to load the mojo 'run' in the plugin 'com.atlassia
n.maven.plugins:maven-amps-dispatcher-plugin:6.2.1' due to an API incompatibility: org.codehaus.plexus.component.repository.exception.ComponentLookupE
xception: com/atlassian/maven/plugins/ampsdispatcher/AmpsDispatcherRunMojo : Unsupported major.minor version 52.0
I tried to run the same on Linux machine i am able to get the success build with the jre 1.7 and atlassian_sdk version 5.0.3. when i am trying to run the same on Windows platform i get the above error. I also tried with jre 1.8 which is a bigtime failure jira refuse to start. so please I need your help here. can you please suggest me what might be the solution for this?
Caused by: java.lang.UnsupportedClassVersionError: com/atlassian/maven/plugins/ampsdispatcher/AmpsDispatcherRunMojo : Unsupported major.minor version
52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(ClassRealm.java:389)
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:42)
at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:259)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:235)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:227)
at org.eclipse.sisu.space.URLClassSpace.loadClass(URLClassSpace.java:107)
... 41 more
Following are the major versions of JRE the class file is compatible with
Java SE 9 = 53
Java SE 8 = 52
Java SE 7 = 51
Check what version of JAVA does your MAVEN is using mvn -version. You should be using jre 1.7
You didn't mention the Jira version you're running, but the error, as mentioned by ravthiru comes from a Java version mismatch. That is you have to use Java 8 for this to work, at least if you stick to the atlas-run and atlas-debug scripts, which use the mentioned com.atlassian.maven.plugins:maven-amps-dispatcher-plugin:6.2.1
which is a bit odd, as that one is included in the plugin-sdk 6.2.2, maybe you updated the sdk? Would you mind having a look inside atlas-run and double check it's 5.0.3?
That plugin was compiled using Java 8, so you either have to do so too or use an older version of the atlassian-plugin-sdk, which was compiled using Java 7. The 5.x versions should work.
Regarding the failure of running Jira with Java 8: Which version are you running, and what errors does it log?

What Version of Maven is Compatible with Java 6?

I have to work in an older project that requires java 6 to run, as there are references to depreciated sun classes that have been removed in future versions. As part of the process, I changed my jdk from 8 in my system path to point to java 6 jdk. After doing so I get:
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/maven/cli/MavenCli : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(ClassRealm.java:401)
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:42)
at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:254)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
at org.codehaus.plexus.classworlds.launcher.Launcher.getMainClass(Launcher.java:144)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:266)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
This is is similar to Maven Installation OSX Error Unsupported major.minor version 51.0 and Exception in thread "main" java.lang.UnsupportedClassVersionError: a (Unsupported major.minor version 51.0) however I'm not looking to upgrade, I'm looking to find a version of maven that is compatible with java 6. Any ideas on which version is compatible and where I can download/install it from for mac?
According to the Maven release history page, the last Maven version that works with JDK1.6 is 3.2.5.
Note that it's better to keep using the newer Maven version (and keep Java 8 as the default in the system path), and tell Maven that the project it's building should compile with source set to 1.6 - see source and target documentation for more info. Reverting to an old Maven will remove the bug fixes / enhancements of the newer versions.
If you have the problem you need to build with JDK 6 but you would like run Maven with JDK 7 (cause you like to use Maven 3.3+) you should consider using toolchain which makes this independent from each other.

Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file in Jenkins

I am using Jenkins ver. 1.565.11.1 (Jenkins Enterprise by CloudBees 14.05) and have JDK 1.5,1.5.0.22,1.6,1.7 all are installed and using different versions for different projects.
My question is I compiled one project with JDK 1.7 by mistake but I have to compile it using jdk 1.5 but not able to do it. Getting below error:
Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(ClassRealm.java:389)
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:42)
at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:259)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:242)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:227)
at jenkins.maven3.agent.Maven31Main.main(Maven31Main.java:138)
at jenkins.maven3.agent.Maven31Main.main(Maven31Main.java:67)
ERROR: Failed to parse POMs
java.io.EOFException: unexpected stream termination
at hudson.remoting.ChannelBuilder.negotiate(ChannelBuilder.java:331)
at hudson.remoting.ChannelBuilder.build(ChannelBuilder.java:280)
at hudson.slaves.Channels.forProcess(Channels.java:114)
at hudson.maven.AbstractMavenProcessFactory.newProcess(AbstractMavenProcessFactory.java:280)
at hudson.maven.ProcessCache.get(ProcessCache.java:236)
at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.doRun(MavenModuleSetBuild.java:755)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:529)
at hudson.model.Run.execute(Run.java:1706)
at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:529)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:232)
Finished: FAILURE
Maven 3.2 requires at least jdk 1.6 for execution.
If you want to use maven 3.2 (or newer) and compile code using the 1.5 jdk, you can look at using toolchains.

Play! Framework run throws UnsupportedClassVersionError

Background, this application is running on Play! Framework 1.2.4 on a Mac OS X 10.5.8
The command I'm running: sudo play run
The exception thrown:
Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:676)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:317)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:280)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:375)
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2357)
at java.lang.Class.getConstructor0(Class.java:2671)
at java.lang.Class.newInstance0(Class.java:321)
at java.lang.Class.newInstance(Class.java:303)
at play.plugins.PluginCollection.loadPlugins(PluginCollection.java:158)
at play.Play.init(Play.java:294)
at play.server.Server.main(Server.java:158)
The application.conf for the application and all dependent modules are set to java.source=1.6
sudo $JAVA_HOME/bin/java -version yields java version "1.6.0_26"
I've even pointed /System/Java/Home to the 1.6 installation.
What else could be causing this?
Which Java version(s) do you have in your PATH? We got a similar issue (not with Play, though) in which all the settings of the application seemed to point to 1.6 but the PATH had a reference to 1.5 that was loaded first due to its position inside the PATH string.
Check your PATH. And, I'm not a Mac user, but it's necessary to use sudo? In Ubuntu I run Play without. If possible, this may help to reduce unexpected conflicts due to root user paths and configuration.

Does jetty 6.1.8 supports jdk 1.5?

Hello i install jetty 6.1.8 on windows for development,
I configure it in eclipse to run with jdk 1.5, and my project is configured to build using the same jdk.
my problem is my project can't be runned using jetty server. it complained the below error message. Please note I can start jetty without error when there is no project added. If I configure jetty to use jdk 1.6, then i can add my project and everything works fine. so does it mean that jetty 6.1.8 doesn't support jdk 1.5?
java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:366)
at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:337)
at org.mortbay.util.Loader.loadClass(Loader.java:91)
at org.mortbay.util.Loader.loadClass(Loader.java:71)
at org.mortbay.jetty.servlet.Holder.doStart(Holder.java:73)
at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:233)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:612)
at org.mortbay.jetty.servlet.Context.startContext(Context.java:139)
at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1220)
at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:510)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at org.mortbay.jetty.deployer.ContextDeployer.deploy(ContextDeployer.java:268)
at org.mortbay.jetty.deployer.ContextDeployer.access$000(ContextDeployer.java:67)
at org.mortbay.jetty.deployer.ContextDeployer$ScannerListener.fileAdded(ContextDeployer.java:89)
at org.mortbay.util.Scanner.reportAddition(Scanner.java:417)
at org.mortbay.util.Scanner.reportDifferences(Scanner.java:331)
at org.mortbay.util.Scanner.scan(Scanner.java:286)
at org.mortbay.util.Scanner$1.run(Scanner.java:246)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
Yes it does: http://www.eclipse.org/jetty/about.php (bottom of the page)
According to this page, Jetty 6.1.x supported Java 1.6. I suspect that you have downloaded Jetty JAR files that were compiled using the Java 1.6 compilers. Get the 1.5 JARs and all should be well.
EDIT: I just downloaded the 6.1.8 ZIP file from here, and the JAR files therein were compiled for Java 1.4 or later (code version #48). You must have picked up a dodgy JAR file from somewhere!

Categories

Resources