#java -version
java version "1.7.0_51"
OpenJDK Runtime Environment (IcedTea 2.4.4) (suse-24.13.5-x86_64)
OpenJDK 64-Bit Server VM (build 24.45-b08, mixed mode)
javac -version
javac 1.8.0_05
I have a trouble with java.Here for example I have “JavaApplication1.java”(simple Hello World example) and
#javac JavaApplication1.java
is done but now
# java JavaApplication1
Exception in thread "main" java.lang.UnsupportedClassVersionError: JavaApplication1 : 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 java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
Depending on what you’re doing, it should not make any difference.
Your post says that you are running openJDK for your JRE
and
likely Oracle Java for your java compiler (javac). I say likely because although you don’t describe where your java compiler came from, it’s kind of unusual to use any but the Oracle compiler and I don’t know if any other than Oracle Java has released a version 8 yet.
The way I see your situation you have 2 options because at the moment there is no recommended procedure to install Java 8 in openSUSE while also using update-alternatives.
If Oracle 8 is important to you, then
Uninstall openJDK from your system
Download Oracle SE 1.8 following the instructions to install (I recommend using the RPM), first the JRE and then the javac. Optional is to also install the web plugin.
If Oracle 8 is not that important to you, installing Oracle SE is very easy, I created some scripts which will have you fully installed in under 30 seconds after you download the Oracle RPM and my scripts.
Since the install will create an update-alternatives configuration, you don’t need to uninstall any previous Java which may exist
Inspect the official openSUSE Java documentation, but <don’t actually follow it>. Instead. click on the “Discussion” tab and click on the link to github where I’ve posted installation scripts I created. This is the link if you just want to click on it here https://github.com/putztzu/openSUSE_Oracle_Java_Install
Follow the instructions, you only need to run each of the scripts in order to install, takes less than 30 seconds and you will have both a working JRE and javac.
In any case, AFAIK Oracle 8 is so new whatever you build may or may not run on someone else’ system unless they update their Java to latest. If you build anything with Java 7, it’ll probably run with the version Java they already have installed.