0

Possible Duplicate:
How to check JRE version prior to launch?

Many people want to know how to force their program to use a minimum version of a jre, but I would like my program to only run using java 6 and not java 7 (aka maximum of jre 1.6). The reason being that my program needs to use FTP, and java 7 has the dreaded FTP bug.

Is there a way to easily make my application run using 1.6 if the user has 1.7 installed?

Some of the options I have looked at are: launch4j

I am not quite certain that it will solve my problem, other than perhaps bundling the entire jre with my program. Which I don't think is the most ideal solution.

Can someone help guide me even down the theoretical path as to how this is generally solved/handled?

Community
  • 1
  • 1
Meeks
  • 21
  • 1
  • 1
  • 3
  • As [this SO post](http://stackoverflow.com/q/6990663/1328439) indicates, the FTP bug can be resolved with a specific change in the Windows 7 firewall configuration (which actually is responsible for the bug that is sometimes ascribed to Java 7). Would not that be an easier solution than forcing an older java version? – Dima Chubarov Sep 29 '12 at 06:21
  • @Dmitri: I would prefer not to have to make my users change their Windows 7 firewall configuration. I have tried using this code within my application, which is a suggested work around: System.setProperty("java.net.preferIPv4Stack" , "true"); However, it seems unreliable, in some situations it works, and in others it doesn't at all. I would like something that reassures me that it will work, not a half measure. – Meeks Sep 29 '12 at 06:34
  • For users tuning up the firewall would be easier than installing previous version of Java. You see: if they come across the problem with FTP, this is not a 100% trouble. But impossibility to run your application (with a message that older version of Java is required) is a very bad experience for the user. They might decide to not run your application at all after this. – Eugene Mayevski 'Callback Sep 29 '12 at 06:45
  • @EugeneMayevski'EldoSCorp: I agree with what you are saying here, and tuning up the firewall could be the lesser of two evils, however I guess I would prefer something that is a good experience for the user all around. But I think my original question was answered, in the sense that trying to force them to use 1.6 is not the way to approach the problem. – Meeks Sep 29 '12 at 06:55

1 Answers1

3

As suggested in this somewhat related question/answer, use System.getProperty("java.version") to see what version of Java is being used to run the application. With this you can make the application prompt the user that he should use an older JRE.

As for running the application without path based JRE detection, the main problem is that you can't be certain where on the user's system the correct JRE is installed. On Windows there's two default possibilities, on *nix it might be anywhere.

If I were you, I'd try to find a custom FTP library that gets around the bug you mentioned to get the maximum security and optimization benefits of the newer versions of Java instead of forcing the user to stay in the past.

Community
  • 1
  • 1
Esko
  • 29,022
  • 11
  • 55
  • 82
  • 1
    And this question covers the topic of FTP client libraries - http://stackoverflow.com/questions/295178/what-java-ftp-client-library-should-i-use – Stephen C Sep 29 '12 at 06:00
  • 1
    I see where you are coming from, and your answer confirms what I suspected. It is probably best to make my code work for both 1.6 and 1.7 so I ultimately don't have to worry for most cases what jre they are using. Annoyingly, there really isn't a current solid work around to the java 7 ftp problem. (The bug I am referring to is discussed here: [Java 7 FTP Bug](http://stackoverflow.com/questions/6990663/java-7-prevents-ftp-transfers-on-windows-vista-and-7-if-firewall-is-on-any-idea)) I guess I will start researching other possible protocols and rewrite that portion of my application. – Meeks Sep 29 '12 at 06:02
  • 1
    @Meeks - you don't need another protocol. You just need a different implementation of the client side. – Stephen C Sep 29 '12 at 06:04
  • Stephen C: How does using a different FTP client library get around the bug? As far as I know, it doesn't, because the problem is with the interaction of windows, IPv6, ftp and java 7. A different library wont change the basic way those things function. – Meeks Sep 29 '12 at 06:10
  • Just to be explicit, I am currently using: org.apache.commons.net.ftp.FTP – Meeks Sep 29 '12 at 06:13