Skip to main content

javac -source 1.6 -target 1.5 [or 1.4 or 1.3]

7 replies [Last post]
jodeleit
Offline
Joined: 2004-10-26

I want to use generics for compile time safty _and_ want to support "old" jdks - like 1.4.

And it would be cool if Mustang / 1.6 / 6.0 would use @Since(major=1,minor=6,micro=0) for classes / packages / methods instead of the "out of fashion" javaDoc tag.

Combined with package annotations for the jar [@jar("rt.jar")] errors could be generated like

> Error: target is 1.5 - usage of "java.lang.String.coolMustangFeature()" is not allowed..

Btw: Does any one know a tool wich converts 1.5 bytecode to 1.4? Should be possible with BCEL...

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ebash
Offline
Joined: 2003-08-09

Sun's Java Compiler has an unducomented target named "jsr14" when used the code compiled can be runned by a 1.4 JRE. This is a quick hack to use some of the Syntaxic Sugar added in 1.5. The problems is that it may not work if you use the new classes or methods introduices in 1.5. So if you want, and know that you will only use some syntax features as the enhanced for loop or the generics there is no problem. As a quick fix you can give it a try but using something as rreyelts is the suggested aproach.

rreyelts
Offline
Joined: 2003-06-10

Right, -target jsr14 is not recommended (by Sun) for production code. It's undocumented, unsupported, subject to change, and doesn't support features like Enums, Iterables or anything else requiring 1.5 runtime support. You'll also find that you quickly run into other problems when trying to combine -target jsr14 and -Xbootclasspath.

God bless,
-Toby Reyelts

monika_krug
Offline
Joined: 2004-10-14

Wow, that's really a cool tool, Toby!

Monika.

rreyelts
Offline
Joined: 2003-06-10

Usually people say, "Retroweaver Rocks", but I'll accept "cool" too. ;)

Seriously, though, if you have any suggestions/feedback please post on the Retroweaver forums.

God bless,
-Toby Reyelts

Message was edited by: rreyelts

rreyelts
Offline
Joined: 2003-06-10

I've written a free tool, Retroweaver - http://retroweaver.sf.net - which does exactly what you're asking for. I've also just finished implementing a new feature, "-verifyrefs", which gives you the exact kinds of warnings you are asking for.

The process is:
1) Compile with a JDK1.5 compiler
2) Run Retroweaver to convert your classes to 1.4
3) Examine any warnings Retroweaver spits out about using classes, methods, or fields, which aren't available.

God bless,
-Toby Reyelts

jodeleit
Offline
Joined: 2004-10-26

Cool, just downloaded it. Will report experiences ;)
It is planned to support 1.3?

rreyelts
Offline
Joined: 2003-06-10

> Cool, just downloaded it. Will report experiences ;)

Well, you might want to check back again in about 24 hours. The latest version will be available with the -verifyrefs option and a built-in Ant task.

> It is planned to support 1.3?

It already supports 1.2 - 1.4.

God bless,
-Toby Reyelts