It seems that you're using an outdated browser. Some things may not work as they should (or don't work at all).
We suggest you upgrade newer and better browser like: Chrome, Firefox, Internet Explorer or Opera

×
I have a HUGE problem, and I think I'm right on the cusp of solving it, but I just hit another roadblock:

I'm trying to make a program in Java, which I haven't used in many years. I got JDK 13 and Eclipse, and they seem to be working fine.

I've made a test program which I can run and debug, and I can also compile it into an executable JAR file, but at first there was no association for that extension, so if I tried to open it Windows wasn't sure what to do.

So I installed the JRE, but the newest version that I could find was 8.something. Now when I try to run the JAR it doesn't work. I get an error that says "Error: A JNI error has occurred, please check your installation and try again."

Then I realized that the problem could be the incompatibility between the JRE version and the JDK version (I think they're supposed to match), but I read that after version 8, there's no longer a JRE at all!

Instead, everything is supposed to be packaged into the JAR, so that it sort of has its own little portable JRE included within it, but with only the necessary files, to avoid having a bunch of unneeded junk with it.

But how can that be possible? If the JRE must be installed to even correctly run the JAR files, then how can it be inside of the JAR files? Or am I severely misunderstanding something?

One thing is that Java is supposed to be cross-platform, so without an external interpreter installed, I don't see how it could be able to run on a bunch of different operating systems! How could that be possible?

So alternatively, I thought that instead of upgrading my JRE to version 13 (which I guess is impossible), I could downgrade my JDK to version 8.

But for some reason, even though Oracle allows people to download version 13, in order to download older versions I must log in (why?), but when I signed up for an account (which supposedly was successfully completed by clicking the link in the e-mail they sent me), every time I try to log in I get an error, so I have no way of downloading it!

I've tried to find the JDK version 8 on other websites to download, but all they seem to have is the JRE of that version!

So PLEASE tell me where I can get JDK version 8 (or any version which is compatible with some JRE version) and/or how to make a JAR file which I could distribute, which would run on any operating system (especially Windows and MacOS) as long as the correct JRE is installed, so that it would be easy for anyone to get it to work anywhere.

Thank you SO MUCH if you can fix this problem!
No posts in this topic were marked as the solution yet. If you can help, add your reply
Actually, I managed to find a JDK for version 8, and got it assigned into Eclipse as the one to use, BUT then my program had new errors and when I tried to run it I got the same error as before: "Error: A JNI error has occurred, please check your installation and try again." I suppose that may be because it failed to compile, so it's now trying to use JRE 8 to run a JAR that had been compiled using JDK 13, but I'm not certain that's the reason.

Anyway, my new error has something to do with a module file which contains very little - pretty much just a module and inside of it there's a line that says it can't find some import or package or something (I'm sorry, but I don't have the code in front of me at the moment, because it's on the other computer).
(I did warn you that just getting the Java code running would be quite a hurdle in itself)

But I would think that a JDK includes the JRE. No idea about file associations, I'm a command line person and would just java -jar myjarfile.jar or something like that. But it's been a while since I touched anything java.
avatar
HeresMyAccount: One thing is that Java is supposed to be cross-platform, so without an external interpreter installed, I don't see how it could be able to run on a bunch of different operating systems! How could that be possible?
That's the thing. Java runs through the Java Virtual Machine of the Java Runtime Environment*, which is why it can run on a multitude of different hardware and software systems (that have such a runtime environment) - for example, Blu-Ray menus are built in Java.

*in some cases, it actually runs through hardware built specifically to run Java, such as on various phones some 15-20 years ago, where running a JVM in software would be too taxing and make even shorter work of the battery life than was already the case.

No environment can by default run binaries not built for that environment - Linux cannot run applications built for Windows, which is why Wine exists in order to have an environment that is sufficiently like Windows, an x86-64 CPU cannot run binaries for a 68000 or a 6502, which is why emulators emulating such hardware exist (in order to run Mac OS classic, and games for Amiga 500, Commodore 64, and Nintendo Entertainment System) - Java is effectively "always run in an emulator" (not quite, but you get he point).

If you have JDK, you per definition also have JRE (everything required to run developed applications is included in the development kit).

Here are downloads of JDK, I see 13, 11, and 8.
By the way, the code in that file looks like:

module
{
requires java.desktop;
}

And the error being generated is "java.desktop cannot be resolved to a module."
avatar
Maighstir: That's the thing. Java runs through the Java Virtual Machine of the Java Runtime Environment*, which is why it can run on a multitude of different hardware and software systems (that have such a runtime environment) - for example, Blu-Ray menus are built in Java.

*in some cases, it actually runs through hardware built specifically to run Java, such as on various phones some 15-20 years ago, where running a JVM in software would be too taxing and make even shorter work of the battery life than was already the case.

No environment can by default run binaries not built for that environment - Linux cannot run applications built for Windows, which is why Wine exists in order to have an environment that is sufficiently like Windows, an x86-64 CPU cannot run binaries for a 68000 or a 6502, which is why emulators emulating such hardware exist (in order to run Mac OS classic, and games for Amiga 500, Commodore 64, and Nintendo Entertainment System) - Java is effectively "always run in an emulator" (not quite, but you get he point).
Yes, I understand all that, but what I don't understand is: if you compile a project into a JAR file using a new version of JDK, such as 13, then because there's no equivalent JRE, suppose you distribute the JAR file so that other people can run it. How can they possibly do so without a JRE? How can it be entirely self-contained if you don't have a program to open JAR files and run them, such as the JRE/JVM/interpreter?
avatar
Maighstir: If you have JDK, you per definition also have JRE (everything required to run developed applications is included in the development kit).
Yes but that's only for versions 8 and earlier, which I now have, but I was using version 13 when I started, which only has a JDK and no JRE. This may have caused some incompatibilities.
avatar
Maighstir: Here are downloads of JDK, I see 13, 11, and 8.
Either you misunderstood or overlooked what I said earlier, because first I said that I'm unable to log into Oracle to download the older versions from their website (I don't know why they require logging in for the old versions but not the new one), and later I said that I have now found the version that I need - 8 (from a different website), but I can't get my code to work with it, because of the error (which is now at the top of this post).
all your problems are "huge" or "urgent" and then theyre always just like code crap
I don't know what that means. Yes, I realize that I say a lot of stuff is urgent, but that's only because I REALLY want to get this working NOW! And I say they're huge, but that's because they're completely preventing me from being able to do what I need to do.
Java got a weird subscription model after Oracle bought it.. As far as I can see (as someone who hasn't used Java in a while) the best thing to do is probably to get rid of JDK 13 and install the 2020 release of JDK 8. That way others can run the programs you build using the publicly available JRE.
2020 JDK 8?! I thought it was much older than that! Where are you getting one that new?
avatar
Fairfox: all your problems are "huge" or "urgent" and then theyre always just like code crap
:)
I can't help starting to suspect a somewhat novel troll, with all these problems.

*sigh*

Anyhu, extending the benefit of doubt:

OP, it sounds like you're possibly getting confused by only reading a marketing blurb about JDK9's jlink, and possibly GraalVM.
Read Oracle's documentation about jlink to see what it actually does.

And the bit about getting older JDKs from Oracle, that's down to those licensing issues that were mentioned in that other thread.
If you want a JDK8, the easiest way (and thus your best bet, IMHO) is to use Amazon's Corretto. It's a good and free version.

With newer Javas, everyone (your end-user included) is supposed to just install the JDK.
avatar
brouer: :)
I can't help starting to suspect a somewhat novel troll, with all these problems.

*sigh*
I SWEAR I'm not a troll! I'm a human being, but I just for some reason happen to be the unluckiest human being in the world, because no matter what I do, nothing EVER goes my way, no matter how simple it should be!

avatar
brouer: Anyhu, extending the benefit of doubt:

OP, it sounds like you're possibly getting confused by only reading a marketing blurb about JDK9's jlink, and possibly GraalVM.
Read Oracle's documentation about jlink to see what it actually does.
Actually I hadn't looked into jlink at all, and I've never even heard of GraalVM. I simply am trying to use the JRE, JDK and IDE (Eclipse) to make a program that will run and also compile into an executable JAR file which will also run.

avatar
brouer: And the bit about getting older JDKs from Oracle, that's down to those licensing issues that were mentioned in that other thread.
If you want a JDK8, the easiest way (and thus your best bet, IMHO) is to use Amazon's Corretto. It's a good and free version.
Well I really don't care about licensing in terms of the legality, because I've already determined that what I'm doing qualifies as "personal use" so there's no problem there. I was able to get the JDK8, but I just had to get it from a different website. Now's the problem of trying to get it to work with a test project, so that I can just compile and run everything.

I'll check out Corretto, but does it have an IDE? Can it act as an alternative to Eclipse so that maybe it won't have the same errors? Today I also tried to run the jar program from the command line using an example that I found from the Internet for parameters to use, but it gave me an error that said it couldn't find a file, even though I specified the files that it needs (but the error flashed on the screen for like a tenth of a second before the command prompt automatically closed, so I had to run the program repeatedly like 30 times, reading a word or two each time until I could figure out what the error was saying - why does the stupid command prompt close automatically???).

avatar
brouer: With newer Javas, everyone (your end-user included) is supposed to just install the JDK.
Do you mean to say that even non-programmers who are just laymen who simply want to run a Java program are intended to install the JDK simply to do so? What are they supposed to do to execute the program - install an IDE like Eclipse and then load the project and click the run button???
avatar
HeresMyAccount: Actually I hadn't looked into jlink at all,
That bit about a JRE with only the necessary files is related to jlink.
Again, look it up, if you want the correct info.quote

Well I really don't care about licensing in terms of the legality
But you asked about the hoops you had to jump through to get a JDK8. Those are down to the licensing issues. Whether *you* care about them is immaterial. They did affect you.
I'll check out Corretto, but does it have an IDE? Can it act as an alternative to Eclipse
It's just a JDK. One that's kept up to date with the latest security fixes and packaged by Amazon.
Licensing issues, you know.
why does the stupid command prompt close automatically???).
How did you open it?
What did you write in it?
If a program exits the calling CMD process, you could try just calling a nested cmd, and run your command there. That way the console window is left open.

Do you mean to say that even non-programmers who are just laymen who simply want to run a Java program are intended to install the JDK simply to do so? What are they supposed to do to execute the program - install an IDE like Eclipse and then load the project and click the run button???
The JDK install includes a JRE. For them it'll work just like it always did.
avatar
HeresMyAccount: 2020 JDK 8?! I thought it was much older than that! Where are you getting one that new?
https://www.oracle.com/technetwork/java/javase/downloads/index.html#JDK8

Java SE 8 was originally released (both JRE and JDK) in 2014, but it was a long-term support version and as such has been receiving updates ever since. The latest update, Java SE 8 Update 241 (or Java SE 8u241 for short) came out 14 January 2020.
Well I don't know what a nested CMD is or how to do it.

When I installed the JDK 13 it didn't include a JRE at all, but when I installed the JDK 8 it did, so I don't see how they could run Java without a JRE any better than I could.

But the great news is, I just created a new project, and evidently, without it trying to use the JDK 13, it had no reason to do some automated crap that it had done before when creating the project, such as make some extra files and folders, and declare some module for some reason. But this time it just made an empty project, and when I made a new class in it, tried some Swing stuff just to test, it ran fine, compiled to a JAR and I could even run that just by double-clicking it!!! WOOHOO!!! Now I think it's just a matter of converting my .NET code to Java and it should theoretically all work correctly after that, and I don't think I'll have any more problems (fingers and toes crossed)!!!!!

Thanks a ton for putting up with me. I know I can be kind of a pain, but please look at it from my perspective: I've had one frustrating setback after another for so many months in a row that I don't even remember what it's like for things to work correctly, but I'm starting to get there!
Glad you got that part working. Good luck for the rest :)