javac -target
I have java version 1.5.0_07 installed. I need to complie my code in version 1.3.
When I do
$ javac -target 1.3 Hello.java
I got:
javac: target release 1.3 conflicts with default source release 1.5
What do I need to change so that I can have a version 1.3 java complied class?
Thanks!
[327 byte] By [
AmyGa] at [2007-10-3 4:18:44]

when Iexplicitly specified the source code version I got this:$ javac -source 1.5 -target 1.3 Hello.javajavac: source release 1.5 requires target release 1.5
AmyGa at 2007-7-14 22:20:29 >

My guess is that you can do it the other way around (-source 1.3, -target 1.5) which will correctly represent the resulting class file as a 1.5 class (even though it was compiled from 1.3 source). However, -source 1.5 implies that bytecode is generated which is not supported by -target 1.3 . Of course, reading the javac man page (or other relevant documentation) will clarify this ;)
Brian
Well, I need the obtain a class file in version JVM 1.3, although my default javac is in v1.5.
Checking this
http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/javac.html
It looks like there is no restriction if I can compile backwards (1.5 to 1.3) or forwards (from 1.3 to 1.5) ?
> My guess is that you can do it the other way around
> (-source 1.3, -target 1.5) which will correctly
> represent the resulting class file as a 1.5 class
> (even though it was compiled from 1.3 source).
> However, -source 1.5 implies that bytecode is
> generated which is not supported by -target 1.3 . Of
> course, reading the javac man page (or other relevant
> documentation) will clarify this ;)
>
> Brian
AmyGa at 2007-7-14 22:20:29 >

I've only been able to compile to lower target JREs with SDK versions that are below 1.5. 1.5 is kind of a huge leap in the Java language.. though I'm not sure why it doesn't support lower targetting even if you don't use 1.5 features (generics, enums, etc.)
this, for example, cannot even compile to 1.3 using a 1.5 SDK:
public class Example {
public static void main(String args[]) {
System.out.println("Hello, World!");
}
}
but with SDK 1.4, I was able to compile it to 1.3..
> Well, I need the obtain a class file in version JVM
> 1.3, although my default javac is in v1.5.
>
safest bet is to download a 1.4 or 1.3 compiler and use that.
> It looks like there is no restriction if I can
> compile backwards (1.5 to 1.3) or forwards (from 1.3
> to 1.5) ?
>
There is. If you use any of the new methods or classes contained in the 5.0 API it will compile fine to a target 1.3 but won't work on 1.3 JVM because it lacks those classes or methods and that includes methods that existed in 1.3 but due to generics or autoboxing might now have different signatures in 1.5 which can (but don't have to) cause runtime failures.
Therefore, the only choice I have is to
install JDK 1.4?
> I've only been able to compile to lower target JREs
> with SDK versions that are below 1.5. 1.5 is kind of
> a huge leap in the Java language.. though I'm not
> sure why it doesn't support lower targetting even if
> you don't use 1.5 features (generics, enums, etc.)
>
> this, for example, cannot even compile to 1.3 using a
> 1.5 SDK:
> > public class Example {
> public static void main(String args[]) {
> System.out.println("Hello, World!");
> }
> }
>
>
> but with SDK 1.4, I was able to compile it to 1.3..
AmyGa at 2007-7-14 22:20:29 >

No, all you have to do is use the 1.3 source level. You can't compile 1.5 source to 1.3 class file, but 1.3 source yes.javac -source 1.3 -target 1.3 MyClass.java
Great. That seems to work!
Is there a way to check the version of the class I just complied?
> No, all you have to do is use the 1.3 source level.
> You can't compile 1.5 source to 1.3 class file, but
> 1.3 source yes.
>
> javac -source 1.3 -target 1.3 MyClass.java
AmyGa at 2007-7-14 22:20:29 >

Not with the tools that come with the JDK or Windows, I guess.
If you use Unix, you can use the file command, for instance a 1.3 compatible class would produce this output:>file Example.class
Example.class: compiled Java class data, version 47.0A 1.5 compatible class would have the version number 49.0.
You can also check the version manually with a hex viewer: a 1.3 class file will start with the bytes "ca fe ba be 00 00 00 2f" while a 1.5 class file with "ca fe ba be 00 00 00 31"
Thanks a lot!
> Not with the tools that come with the JDK or Windows,
> I guess.
>
> If you use Unix, you can use the file command, for
> instance a 1.3 compatible class would produce this
> output:>file Example.class
> Example.class: compiled Java class data, version
> 47.0A 1.5 compatible class would have the
> version number 49.0.
>
> You can also check the version manually with a hex
> viewer: a 1.3 class file will start with the bytes
> "ca fe ba be 00 00 00 2f" while a 1.5 class file with
> "ca fe ba be 00 00 00 31"
AmyGa at 2007-7-14 22:20:29 >
