Need to update to Java Runtime 62.0 -- not sure how to do it

Straitsfan

New Member
Joined
Dec 13, 2021
Messages
3
Reaction score
0
Credits
66
Hello. I've dabbled with Linux in the past, but my MB pro is dying -- started yesterday, in fact -- and it's time to switch. I have experience with the command line in the Terminal app, so most of the commands -- at least the basic ones -- I'm familiar with in Linux.

I 'm running elementary OS, and was able to download and install the Open JDK for Java 17. I'm working on a project as a way of learning Java. I have a folder labeled "Contacts Java Classes", and I know how to get to the folder, etc. There's a file that I want to run which contains the main method to get things going -- "MainWIndow.java" I can compile the file. Before when I tried to run the file w/o compiling I got this error:

Error: LinkageError occurred while loading main class MainWindow
java.lang.UnsupportedClassVersionError: MainWindow has been compiled by a more recent version of the Java Runtime (class file version 62.0), this version of the Java Runtime only recognizes class file versions up to 61.0

I was able to compile the file, and then I got this error when I entered "java MainWindow":

Exception in thread "main" java.lang.UnsatisfiedLinkError: Can't load library: /usr/lib/jvm/java-17-openjdk-amd64/lib/libawt_xawt.so
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2393)
at java.base/java.lang.Runtime.load0(Runtime.java:755)
at java.base/java.lang.System.load(System.java:1953)
at java.base/jdk.internal.loader.NativeLibraries.load(Native Method)
at java.base/jdk.internal.loader.NativeLibraries$NativeLibraryImpl.open(NativeLibraries.java:388)
at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:232)
at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:174)
at java.base/jdk.internal.loader.NativeLibraries.findFromPaths(NativeLibraries.java:315)
at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:285)
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2398)
at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:818)
at java.base/java.lang.System.loadLibrary(System.java:1989)
at java.desktop/java.awt.Toolkit$2.run(Toolkit.java:1392)
at java.desktop/java.awt.Toolkit$2.run(Toolkit.java:1390)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
at java.desktop/java.awt.Toolkit.loadLibraries(Toolkit.java:1389)
at java.desktop/java.awt.Toolkit.initStatic(Toolkit.java:1427)
at java.desktop/java.awt.Toolkit.<clinit>(Toolkit.java:1401)
at java.desktop/java.awt.Component.<clinit>(Component.java:624)
at MainWindow.<init>(MainWindow.java:10)
at MainWindow.main(MainWindow.java:52)

Everything works fine on my MB Pro. But even thought I've dabbled before in Linux -- and I just mean dabble, since I always had my OS X -- I'm not sure what's going on.

Should I upgrade to Java 18? And if so, what's the best way to do it? Can anyone help me out? I'v been on other forums, but I'm not sure what I need to sak, and I think I may have gotten under some people's skin. The installing on OS X is easy, but it's more complicated here in Linux, and I'm not sure where to go.

I currently have the open JDK version, but there are versions on Oracle's site (Are they the same thing?). I tried downloading and installing them once last December, but I wasn't sure how to proceed, which versions I needed, and it was somewhat confusing trying to find the answers on the web.

Please offer me any assistance if you can.
 


gvisoc

Well-Known Member
Joined
May 29, 2020
Messages
416
Reaction score
485
Credits
4,265
Can you post the following, to start with?
  • The output of the command alternatives --display java.
  • The output of the command echo $JAVA_HOME
  • The output of the commands java -version and javac -version
Thanks
 
Last edited:

gvisoc

Well-Known Member
Joined
May 29, 2020
Messages
416
Reaction score
485
Credits
4,265
Also: how are you building the program? Are you using a build automation tool like Maven or Gradle? Are you invoking javac from the terminal? Are you building it from within an IDE?
 
OP
S

Straitsfan

New Member
Joined
Dec 13, 2021
Messages
3
Reaction score
0
Credits
66
Don't know what Maven or Gradle is. Not buliding from an IDE.

terminal can't find the commend alternatives. Managed to install galternatives, but got this:
galternatives --display java
Unable to init server: Broadway display type not supported: java
Unable to init server: Broadway display type not supported: java

echo JAVA_HOME gives no result, just a blank line, then back to the command line.

java -version
java version "18.0.1.1" 2022-04-22
Java(TM) SE Runtime Environment (build 18.0.1.1+2-6)
Java HotSpot(TM) 64-Bit Server VM (build 18.0.1.1+2-6, mixed mode, sharing)
Managed to get other help to install java 18, so I'm not sure if it's even worth trying to update version 17.

javac -version
javac 17.0.3
 

gvisoc

Well-Known Member
Joined
May 29, 2020
Messages
416
Reaction score
485
Credits
4,265
Try update-alternatives instead; as elementary is a fork from Ubuntu, they may use that command instead.

The problem you have is that you have Java 18 runtime and Java 17 SDK installed, and you’re compiling with one but running with the other. When you compile with the lower version and you run with the higher, it should work though.

To have the same version for both, you can either set JAVA_HOME (for what the output of update-alternatives is useful, as it tells us where each version is installed), or upgrade the SDK to Java 18.

Not sure what the packages are in elementary, though, but try to do a search in its software manager.
 
Last edited:
$100 Digital Ocean Credit
Get a free VM to test out Linux!

Linux.org Hosting Donations
Consider making a donation

Members online

No members online now.

Top