I’m writing a program that needs to watch for file system events on multiple platforms. Java 7 includes a new standard library, WatchService, that acts as an abstraction for the different types of filesystem event handlers (inotify, FSEvents, FileSystemWatcher etc).
Is it the case that code compiled with the Java 7 compiler needs a Java 7 JVM to run it?
If so, will I have all sorts of problems with client machines that don’t have JVM 7 installed/available for that platform (older OSXs, Windows XP etc)?
Yes.
You would be able to use a Java 7 compiler to compile with
-target 6.0, but that won’t help if the code depends on Java 7 – specific class libraries … as yours apparently does.Yes. That is certainly the case on the “installed” front. If your code depends on Java 7, the best option is to get your customers to install a Java 7 JVM to run it. (It is a simple matter to install multiple versions of Java side-by-side, and there’s a good chance that other Java apps will run fine with a Java 7 JVM.)
On the “available” front, we won’t know for sure which platforms will be supported until Oracle actually releases Java 7. If there are significant platforms that are not supported, there is a good chance that either:
(But I wouldn’t bet on anyone supporting Windows pre-XP, and old versions of OSX are doubtful, IMO.)
My advice would be not to “jump” to Java 7 … yet … if supporting old platforms is an important requirement.