Z
zyng
Hi,
I have asked the similar question before. Thank you for all your help. The issue is still not solved and is very mysterious. By many testing, I have obtained new observations. I think I can ask this question in a better way. Thank you for your help.
As everybody knows, rt.jar is located in jre/lib/ directory. It is *automatically* loaded into Java runtime platform. My code uses some classes in rt.jar. (Whether this is wise or not, this is different issue. Here, I just hope to solve the classpath issue related to rt.jar.)
To check rt.jar is *automatically* loaded by Java, in ant script compile target, I added the option "-verbose". This shows all path of the classes referenced:
<target name="compile" depends="prepare">
<javac srcdir="${src.dir}" destdir="${build.dir}" compiler="modern"fork="yes" debug="on">
<classpath refid="project.classpath"/>
<compilerarg value="-Xlint"/>
<compilerarg value="-verbose"/>
</javac>
</target>
The printout shows that indeed all those JAR files inside jre/lib are loaded:
[javac] [search path for class files: /A/B/jdk1.6.0_25/jre/lib/resources.jar,/A/B/jdk1.6.0_25/jre/lib/rt.jar,/A/B/jdk1.6.0_25/jre/lib/sunrsasign.jar ...
However, I need this to compile successfully:
<path id="project.classpath">
<fileset dir="/A/B/java/">
<include name="jre/lib/rt.jar"/>
</fileset>
...
</path>
The print out shows
[javac] [search path for class files: /A/B/jdk1.6.0_25/jre/lib/resources.jar,/A/B/jdk1.6.0_25/jre/lib/rt.jar,/A/B/jdk1.6.0_25/jre/lib/sunrsasign.jar ..., ...,/A/B/java/jre/lib/rt.jar, ..
(/A/B/java is a solft link to /A/B/jdk1.6.0_25)
To make my story short, my findings is that in order to compile, rt.jar must shows up twice and the path must be different from the first time by these observations:
1) this won't compile:
<path id="project.classpath">
<fileset dir="/A/B/jdk1.6.0_25/">
<include name="jre/lib/rt.jar"/>
</fileset>
...
</path>
[javac] [search path for class files: /A/B/jdk1.6.0_25/jre/lib/resources.jar,/A/B/jdk1.6.0_25/jre/lib/rt.jar,/A/B/jdk1.6.0_25/jre/lib/sunrsasign.jar ..., ...,/A/B/jdk1.6.0_25/jre/lib/rt.jar, ..
(the second time rt.jar path is exactly same as the first time, it seems java didn't bother to re-load rt.jar -- my understanding)
2)this will work(copy rt.jar to rt2.jar before hand):
<path id="project.classpath">
<fileset dir="/A/B/jdk1.6.0_25/">
<include name="jre/lib/rt2.jar"/>
</fileset>
...
</path>
[javac] [search path for class files: /A/B/jdk1.6.0_25/jre/lib/resources.jar,/A/B/jdk1.6.0_25/jre/lib/rt.jar,/A/B/jdk1.6.0_25/jre/lib/sunrsasign.jar ..., ...,/A/B/jdk1.6.0_25/jre/lib/rt2.jar, ..
(java loads rt2.jar, now my code compiles successfully)
3)this will work(copy jre/lib to somewhere else beforehand)
<path id="project.classpath">
<fileset dir="/X/Y/">
<include name="jre/lib/rt.jar"/>
</fileset>
...
</path>
[javac] [search path for class files: /A/B/jdk1.6.0_25/jre/lib/resources.jar,/A/B/jdk1.6.0_25/jre/lib/rt.jar,/A/B/jdk1.6.0_25/jre/lib/sunrsasign.jar ..., ...,/X/Y/jre/lib/rt.jar, ..
(again, the path of the second time referencing rt.jar is different, java then load rt.jar into the platform and my code compiles successfully)
My feeling is that the first time rt.jar loaded, the classes inside rt.jar cannot be accessed by my code. The second time referencing rt.jar, if everything is exactly same as the first reference(including path and the file name), java skips the loading; if there is some difference(different path or different file name) comparing to the first reference, java loads this JAR into the platform, then my code can compile.
Can you help me understand this? I really hope that in the ant script, rt.jar no need to be referenced.
Thank you very much.
I have asked the similar question before. Thank you for all your help. The issue is still not solved and is very mysterious. By many testing, I have obtained new observations. I think I can ask this question in a better way. Thank you for your help.
As everybody knows, rt.jar is located in jre/lib/ directory. It is *automatically* loaded into Java runtime platform. My code uses some classes in rt.jar. (Whether this is wise or not, this is different issue. Here, I just hope to solve the classpath issue related to rt.jar.)
To check rt.jar is *automatically* loaded by Java, in ant script compile target, I added the option "-verbose". This shows all path of the classes referenced:
<target name="compile" depends="prepare">
<javac srcdir="${src.dir}" destdir="${build.dir}" compiler="modern"fork="yes" debug="on">
<classpath refid="project.classpath"/>
<compilerarg value="-Xlint"/>
<compilerarg value="-verbose"/>
</javac>
</target>
The printout shows that indeed all those JAR files inside jre/lib are loaded:
[javac] [search path for class files: /A/B/jdk1.6.0_25/jre/lib/resources.jar,/A/B/jdk1.6.0_25/jre/lib/rt.jar,/A/B/jdk1.6.0_25/jre/lib/sunrsasign.jar ...
However, I need this to compile successfully:
<path id="project.classpath">
<fileset dir="/A/B/java/">
<include name="jre/lib/rt.jar"/>
</fileset>
...
</path>
The print out shows
[javac] [search path for class files: /A/B/jdk1.6.0_25/jre/lib/resources.jar,/A/B/jdk1.6.0_25/jre/lib/rt.jar,/A/B/jdk1.6.0_25/jre/lib/sunrsasign.jar ..., ...,/A/B/java/jre/lib/rt.jar, ..
(/A/B/java is a solft link to /A/B/jdk1.6.0_25)
To make my story short, my findings is that in order to compile, rt.jar must shows up twice and the path must be different from the first time by these observations:
1) this won't compile:
<path id="project.classpath">
<fileset dir="/A/B/jdk1.6.0_25/">
<include name="jre/lib/rt.jar"/>
</fileset>
...
</path>
[javac] [search path for class files: /A/B/jdk1.6.0_25/jre/lib/resources.jar,/A/B/jdk1.6.0_25/jre/lib/rt.jar,/A/B/jdk1.6.0_25/jre/lib/sunrsasign.jar ..., ...,/A/B/jdk1.6.0_25/jre/lib/rt.jar, ..
(the second time rt.jar path is exactly same as the first time, it seems java didn't bother to re-load rt.jar -- my understanding)
2)this will work(copy rt.jar to rt2.jar before hand):
<path id="project.classpath">
<fileset dir="/A/B/jdk1.6.0_25/">
<include name="jre/lib/rt2.jar"/>
</fileset>
...
</path>
[javac] [search path for class files: /A/B/jdk1.6.0_25/jre/lib/resources.jar,/A/B/jdk1.6.0_25/jre/lib/rt.jar,/A/B/jdk1.6.0_25/jre/lib/sunrsasign.jar ..., ...,/A/B/jdk1.6.0_25/jre/lib/rt2.jar, ..
(java loads rt2.jar, now my code compiles successfully)
3)this will work(copy jre/lib to somewhere else beforehand)
<path id="project.classpath">
<fileset dir="/X/Y/">
<include name="jre/lib/rt.jar"/>
</fileset>
...
</path>
[javac] [search path for class files: /A/B/jdk1.6.0_25/jre/lib/resources.jar,/A/B/jdk1.6.0_25/jre/lib/rt.jar,/A/B/jdk1.6.0_25/jre/lib/sunrsasign.jar ..., ...,/X/Y/jre/lib/rt.jar, ..
(again, the path of the second time referencing rt.jar is different, java then load rt.jar into the platform and my code compiles successfully)
My feeling is that the first time rt.jar loaded, the classes inside rt.jar cannot be accessed by my code. The second time referencing rt.jar, if everything is exactly same as the first reference(including path and the file name), java skips the loading; if there is some difference(different path or different file name) comparing to the first reference, java loads this JAR into the platform, then my code can compile.
Can you help me understand this? I really hope that in the ant script, rt.jar no need to be referenced.
Thank you very much.