Bootstrap Classpath [message #25401] |
Sat, 05 February 2005 02:07 |
Eclipse User |
|
|
|
How can I explicitly control the bootstrap classpath for a java compile
under Eclipse?
I see that I am able to influence the Compliance using preferences -> java
-> compiler then selecting the Compliance and Classfiles Tab but I think I
need to also control the bootstrap classpath to force the compiler to
generate the correct byte code. I am using Eclipse 2.1.3
My problem is I am using a 1.4.2_06 JRE and want to target a minimum 1.3.1
runtime. Under the Compliance and Classfiles Tab I have specified 1.3 for
compliance, 1.3 for Generated .class files and 1.3 for Source
compatibility but the eclipse java compiler is generating byte code that
fails under a 1.3.1 JRE.
The following sample code should serve as an example:
public class Hello
{
public static void main (String [] args)
{
StringBuffer greeting = new StringBuffer ("hello, ");
StringBuffer who = new StringBuffer (args [0]).append ("!");
greeting.append (who);
System.out.println (greeting);
}
When the above code is compiled under Eclipse using a 1.4.2_06 jre to
target a 1.3.1 runtime it compiles with no errors (as it should, the
source is 100% java 1.0 compatible). When it is run under a 1.3.1 jre it
complains about a missing method.
J2SE 1.4 added a new method to the StringBuffer API: append(StringBuffer).
When the compiler decides how to translate greeting.append (who) into byte
code, it looks up the StringBuffer class definition in the bootstrap
classpath and selects this new method instead of append(Object). Even
though the source code is fully Java 1.0 compatible, the resulting byte
code requires a J2SE 1.4 runtime.
|
|
|
Powered by
FUDForum. Page generated in 0.07246 seconds