• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Cannot cross-compile for 1.4 from Java 6

 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All!

This is the first time I have actually needed to cross-compile my code for a different JVM version, and I'm having a few problems. If using Java 6 version of javac:

If I try the following command, all is well (@sourcefiles is a list of files to compile):
javac -d build/ -target 1.5 @sourcefiles
But, this command fails:
javac -d build/ -target 1.4 @sourcefiles
with the error: javac: target release 1.4 conflicts with default source release 1.5
Ignoring the bug in the error message about "default source release 1.5" (should be 1.6), does anyone know why I cannot compile for 1.4? I know to use the -bootclasspath to compile against the 1.4 version of rt.jar, I just left it off for clarity.

Thanks,

Darrin
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try:

javac -source 1.4 -target 1.4 ...

In Java 5, a number of new features were added to the language, such as generics, autoboxing, etc. You must tell the compiler that your source code is Java 1.4 source code. Note that it will not compile if you are using Java 5 language features.

Also, if you are using Java API classes or interfaces that were added in a Java version newer than 1.4, your code will compile, but it will not run on a version 1.4 JRE (you'll get a NoClassDefFoundError sooner or later when your program tries to use a class that's not in the Java 1.4 API).

It's safer to download JDK 1.4 and compile your source code with the JDK 1.4 compiler; that way, you'll get a compiler error if you're using a class that's not in the Java 1.4 API.
[ May 31, 2007: Message edited by: Jesper Young ]
 
Darrin Cartwright
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jesper.

Looks like I'm out of luck. We ported all of our Java code to use 1.5/1.6 language features, only to find out that it needed to run on Windows NT (yuk!), which is only supported by Java 1.4.
I was hoping the compiler could create 1.4 compatible bytecode from 1.5 or 1.6 source code. I guess this is not possible?

Thanks again,
Darrin
 
Darrin Cartwright
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, a little more searching turned up a few ways to do what I wanted,

1. Use an undocumented compiler flag "-target jsr14" to create 1.4 compatible bytecode, but you still have to remove classes and methods that did not exist in 1.4 (which makes perfect sense).
2. Use retrotranslator to convert to 1.4 bytecode, and supply the missing 1.5 class definitions!
3. Use Retroweaver to convert to 1.4 bytecode, and again remove unknown classes and methods.

Should be interesting! :roll:
Thanks again Jasper!

Darrin
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic