File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Cross Compilation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Cross Compilation" Watch "Cross Compilation" New topic

Cross Compilation

Swapnil Shroff
Ranch Hand

Joined: Mar 07, 2006
Posts: 58
I am trying to do a Cross Compilation using JDK 1.5 for legacy application that was build with jdk 1.3.

This we are doing to achive any performace benefits using new compiler.

I have an issue with the classes that 1.5 uses as the code is not compatible with new jars(tools.jar/rt.jar etc) in 1.5.

For example
1.5 has a new Formatter class and our application code also has a Formatter class. The references are not properly resolved due to * usage in code.

Now we cannot change the code for resolving the references.

So my query is can i change the jars that 1.5 uses to the jars from 1.3. Tthis works fine for compilation.


My view-->

As i understand, for Cross Compilation(performance gains) what really should matter is the compiler. So if we are changing the jars than also we are cross compiling.

any inputs are welcomed.

Thanks in advance.

SCJP 5, SCDJWS<br /> <br />It's amazing how premature optimisation is both seductive and destructive; even when you know
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Hmm. Seems a bizarre idea to me.

I thought performance gains in later Java versions came mainly from: -

  • Improvements to the JVM (HotSpot, garbage collection etc.)
  • Improvements to the API classes

  • You won't get any of those. Your program will be running with a JVM from Java 1.3 and it will be using the API classes from 1.3.

    You'll only get any improvements there may have been to the generated byte-code. I've never heard anyone suggest there have been big (or even small) improvments in this area.

    Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
    Swapnil Shroff
    Ranch Hand

    Joined: Mar 07, 2006
    Posts: 58
    Thanks Peter for reply.

    You won't get any of those. Your program will be running with a JVM from Java 1.3 and it will be using the API classes from 1.3.

    We are not looking for any runtime performance gains but at the compile time. At runtime we will use 1.3 JRE.

    Actually we have a huge legacy code(14 thousand java files) and it take around 2 hours for building(compiling). we are trying to reduce this time by using cross compilation.

    so what would be the effect of using 1.3 jars with 1.5 compiler
    Jesper de Jong
    Java Cowboy
    Saloon Keeper

    Joined: Aug 16, 2005
    Posts: 15084

    The Java compiler and JDK have not been designed to work like this (using 1.3 JARs with the 1.5 compiler), so it's not certain that it's even possible, and your might get strange problems either at compile time or at runtime.

    There's no official way to make this work and even if you manage to get it working, there's no guarantee that you'll get strange problems with the compiled classes.

    If this is for a production code on a commercial, business project I would not take the risk to try something strange and unsupported like that.

    Instead, I would first focus on finding ways to avoid the need to recompile the code so often. Is it really necessary to compile all those 14,000 source files so often? Is there a way to organize the sources in such a way that you only have to compile a small part if you make a change? Can you maybe setup a separate server which does the compiling at a moment when people don't have to wait for it (a nightly build, for example)?

    (Ofcourse the compiler has "-source" and "-target" switches so that you can compile classes that are compatible with 1.3, but those unfortunately don't stop you from using Java 1.4+ API classes).

    Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
    Swapnil Shroff
    Ranch Hand

    Joined: Mar 07, 2006
    Posts: 58
    But this is what -bootclasspath and -extdirs option is used for
    Mahboob Ali

    Joined: Oct 04, 2013
    Posts: 3
    Cross Compilation with Respect to jdk7
    step:1 --create a java file

    step:2 --compile the above by using following command in windows cmd command i am compiling jdk1.6 using jdk1.7.

    before applying this command please make sure that your your should contains or points to the actual rt.jar file of intended jdkX.X(1.1 or 1.2 or 1.3 or 1.4 or 1.5 or 1.6 etc)of and folder name should not contains spaces for example like in windows default place to be installation of softwares is here program files folder name have spaces.
    means the file contained source like enhanced for loop feature introduced in jdk1.5v like wise there may be possibility of your .java file may have some code specific to that jdk versions.
    note that it is always as same as .
    describes the your converted type means cross compilation type. here i am using jdk7 , hence to make jdk1.6 compiler available in jdk1.7 i used this option.
    I agree. Here's the link:
    subject: Cross Compilation
    It's not a secret anymore!