3

I realize this isn't 100% relevant yet, but I'm very curious about this. In JDK8, javac parameters "source" and "target" are deprecated, and will be removed in JDK9. As a JavaME developer, I'm wondering how then I'll be able to target older platforms. For example, I'm using target 1.3 when developing for Blu-ray. How do I compile my Xlets for Blu-ray when JDK9 is out if there's no "target" option? I imagine there must also be other (although we can agree not a lot) people out there still needing to target older devices. What do we do when JDK9 is out?

EDIT: Is it even possible to target 1.3 with JDK9?

mr_lou
  • 1,871
  • 2
  • 12
  • 25

2 Answers2

5

To answer the question "how to compile without the target option", the new -release flag is a safer and more reliable alternative to -source and -target. See JEP-247 for more details. You will target older platforms with -release the same way you would with -source and -target.

The statement "source and target will be removed in JDK9" is sort of true but not quite: the -source and -target flags themselves are not removed, but their use to target specific older versions is deprecated. From JEP-182: "in JDK 9, support for a source or target of 1.5 or earlier will be removed."

To answer the question "is it even possible to target 1.3 with JDK9?" The answer is that with regards to the -release flag, JDK9 will not compile to target 1.3.

From javac -help:

--release <release>
      Compile for a specific VM version. Supported targets: 6, 7, 8, 9

Your best option is to compile with an older version of the JDK. If you need to target 1.3, there's not a lot of reason to use the Java 9 compiler anyway.

Jay
  • 6,684
  • 3
  • 36
  • 44
  • That's good news, although a bit puzzling. They remove "source" and "target" in order to reduce maintenance cost of javac - and then just introduce another parameter which basically does the same? Oh well, as long as I can compile my Xlets to a Blu-ray compatible jar file, then I'm happy. I suppose time will tell if this new approach does something different, which makes my jar files incompatible with Blu-ray specs. – mr_lou Sep 24 '16 at 06:18
  • From the JEP: "By default javac compiles against the most-recent version of the platform APIs. The compiled program can therefore accidentally use APIs only available in the current version of the platform. Such programs cannot run on older versions of the platform, regardless of the values passed to the -source and -target options. This is a long-term usability pain point, since users expect that by using these options they'll get class files that can run on the specified platform version." – Jay Sep 24 '16 at 16:06
  • Just want to be clear that the new flag has a very specific reason, and that it's an improvement over the original flags. They're not just changing stuff around because they feel like it :) – Jay Sep 24 '16 at 16:08
  • The JEP does not use the word _replace_, which makes this answer misleading as it seems to corroborate the question's false claim that they are deprecated. – Nicolai Parlog Sep 25 '16 at 10:46
  • I've removed the word "replace". Is the answer better worded now? – Jay Sep 26 '16 at 18:40
  • Had to undo the accepted answer, since the "release" parameter still doesn't let me go as far back as I want; to target 1.3 – mr_lou Sep 30 '16 at 09:04
  • 1
    I've edited the answer to reflect the changes to your question. – Jay Sep 30 '16 at 19:24
1

I am unaware of -source and -target being deprecated in Java 8 and removed in Java 9 - the early access build (at least 9-b131) still has them. Do you have a source for that?

The only change in that area I know of is JEP 247, which introduces -release, which is kind of a shortcut for the other two.

Nicolai Parlog
  • 36,673
  • 16
  • 109
  • 236
  • You should pose a new question for that, focusing on the "one + three back" rule described in [JEP 182](http://openjdk.java.net/jeps/182). – Nicolai Parlog Sep 25 '16 at 10:48
  • No need if the new "release" flag let's me go back to 1.3 – mr_lou Sep 25 '16 at 13:26
  • 1
    There is no reason to believe that it will let you go back to anything that `-source` and `-target` don't support. And according to [JEP 182](http://openjdk.java.net/jeps/182) 1.3 will not be supported on javac 9. – Nicolai Parlog Sep 30 '16 at 06:30