Domanda

I wrote the Swing program in Java 8. It, of course, does not run on machines which have Java 7 on them. Is there a way to prompt the user, when he or she tries to run the .jar file, that Java 8 is required to run the program, preferably, by showing the dialog window with this prompt.

È stato utile?

Soluzione

Create a new java 7 file that checks the users java version using System.getProperty("java.version") and then if it comes back as 8 then the java 7 file can start the java 8 file, if not it can send out a dialog box telling the user to upgrade.

Altri suggerimenti

If I remeber correctly, Launch4J could check for the correct JRE and would probably show some error message if the JRE could not be found. However, I do not know whether it works with Java 8.

This would also only work for Windows though.

I don't like the idea of a 2nd "launcher" jar/class that's written/compatible with a lower version of Java. That means that I have to keep this old version around indefinitely, which may be problematic since:

  • I need to know how old a version the launcher jar must be to cover all potential users.
  • I now need to support 2 versions of Java for my builds.
  • The old version may be insecure, and possibly EOL, with no hope of patches/fixes.
  • Java started embedding expiration dates in the version.

Consider launching your app via Java Web Start. This works on all platforms (I believe), and will handle the version checking for you.

Another alternative is to write a wrapper script (not written in Java) that launches your app. It could check for the presence and value of an environment variable (perhaps JAVA_HOME).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top