Compile to Java 1.5 bytecode

171 views
Skip to first unread message

zemly...@gmail.com

unread,
Oct 3, 2016, 4:48:48 AM10/3/16
to bazel-discuss
I need to compile Java code for embedded device that runs Java 1.5 VM.

On the host I'm using JDK8 that allows to compile Java 1.5 sources to Java 1.5 bytecode with the help of "-source 1.5" and "-target 1.5" javac options. I pass these options to Bazel with --javacopt="-source 1.5" --javacopt="-target 1.5" arguments.

But Bazel uses some kind of wrapper that does not allow these options:
error: Source option 1.5 is no longer supported. Use 1.6 or later.
error: Target option 1.5 is no longer supported. Use 1.6 or later.

I believed that it is possible to specify my own toolchain that uses system installed JDK with "java_toolchain" rule but seems that purpose of this rule is different.

How can I compile to Java 1.5 bytecode? Is it even possible with Bazel?

Damien Martin-guillerez

unread,
Oct 4, 2016, 9:23:42 AM10/4/16
to zemly...@gmail.com, bazel-discuss
Hi,

Java 1.5 is no longer supported by JDK 8, can you tell us why you would like to target a JVM 1.5?

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/9f57454e-4834-4e60-bff5-d67d5b309087%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

zemly...@gmail.com

unread,
Oct 4, 2016, 10:03:29 AM10/4/16
to bazel-discuss, zemly...@gmail.com
JDK8 still supports target JVM 1.5. Compiler shows that this option is obsolete and might be removed in future releases, but the option still works. Class files are generated with version id "49" that corresponds Java 1.5 as expected.

My embedded device runs old VM that supports Java 1.5 only. Initially I used
JDK 1.5 to compile to Java 1.5 bytecode.

But Bazel requires JDK8 and uses the same JDK to compile Java code. This forced me to move to JDK8 and as a result I have the original problem. This problem actually blocks transition from make/ant to Bazel.

Eddie Aftandilian

unread,
Oct 4, 2016, 1:12:36 PM10/4/16
to zemly...@gmail.com, bazel-discuss
We are actually using a javac 9 for Bazel (packaged with Bazel rather than the one from your JDK), so it doesn't support Java 1.5.  

To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/02422da2-f197-4d97-8a5e-381571827fef%40googlegroups.com.

zemly...@gmail.com

unread,
Oct 5, 2016, 4:54:14 AM10/5/16
to bazel-discuss, zemly...@gmail.com
Eddie, thanks for answer.

I'm just curious. What are the reasons of packaging Java compiler to Bazel installation on the one hand and requirement to have JDK8 (not JRE!) installed in a system on the other hand?

Damien Martin-guillerez

unread,
Oct 5, 2016, 5:12:28 AM10/5/16
to zemly...@gmail.com, bazel-discuss
We need to package the Java compiler to be able to run a Javac 9 on JRE 8 which is the version that is compatible with our javac wrapper and errorprone. We need the JDK to be able to access the classpath.

The solution to this problem might be use the Skylark rules for java but you will not get as much support as you get with our rules: https://github.com/bazelbuild/bazel/blob/master/tools/build_rules/java_rules_skylark.bzl


Alex Humesky

unread,
Oct 5, 2016, 3:14:48 PM10/5/16
to Damien Martin-guillerez, zemly...@gmail.com, bazel-discuss
You could alternatively try taking the java 8 bytecode and backporting it to java 5 using a tool like retrolambda: https://github.com/orfjackal/retrolambda 

Reply all
Reply to author
Forward
0 new messages