📜 ⬆️ ⬇️

We collected the debug-version of rt.jar

Why do you need it?

So instead of this:

image
')
when debugging standard java library see this >>


image

Made on the basis of approaches described by reference:

www.javalobby.org/java/forums/t103334.html
forums.sun.com/thread.jspa?threadID=428018&tstart=1620
www.javalobby.org/java/forums/t19866.html

How? In a nutshell: recompile src.zip from the JDK with the compiler option -g specified .

Prerequisites: installed JDK & python.

Step by step. Create somewhere an empty daddy, for definiteness D: / rt_debug, unzip src.zip and rt.jar from your JDK installation into it. I did this procedure with a freshly installed jdk-6u20. Thus, in D: / rt_debug you will get 2 folders D: / rt_debug / rt and D: / rt_debug / src. Create a gen_compile_files_list.py script in the same folder as follows:

from os import walk
from os.path import join

def find(path, ext):
for dir, _, files in walk(path):
for f in files:
if f.endswith(ext):
yield join(dir, f)

#print '\n' .join(find( 'src' , '.java' ))

def go():
src_files = list(find( 'src' , '.java' ))
rt_files = list(find( 'rt' , '.class' ))

n_src = len(src_files)
n_rt = len(rt_files)

print 'java files:' , n_src
print 'rt files:' , n_rt

src_files=[s[4:-5] for s in src_files] # src/qqq.java -> qqq
rt_files = set ([s[3:-6] for s in rt_files ]) # rt/qqq. class -> qqq

out = open( "to_compile.txt" , "w" )

to_compile = 0
obsolete = 0

for j in src_files:
f = "%s.java\n" % j
if j in rt_files:
out .write(f)
to_compile += 1
else :
#print "Obsolete: " , f
obsolete += 1

print 'will compile:' , to_compile
print 'obsolete:' , obsolete

out .close()

go()

* This source code was highlighted with Source Code Highlighter .


This code will generate a compiled list of .java files in the to_compile.txt file. The fact is that src.zip as it turned out has some source code that is not in rt.jar (so I think for backward compatibility?), The presence of which breaks the compilation.

After running the script, you will have the file to_compile.txt. Then, create a c.bat file with the following content (correct the paths to your java_home):

@echo off

set JH=C:/Program Files/Java/jdk1.6.0_20
set VER=1.6

if not exist classes (
echo Creating classes dir
mkdir classes
)

echo Compiling...

cd src
"%JH%\bin\javac" -nowarn -g -d ../classes -J-Xmx512m -classpath ../rt -source %VER% -target %VER% @../to_compile.txt 2>../error.log

echo Creating jar...

cd ../classes
"%JH%\bin\jar" -cf ../rt-dbg.jar *

cd ..

echo Done.


* This source code was highlighted with Source Code Highlighter .


or, if you are a Linux user, then c.sh content:

JH= "C:/Program Files/Java/jdk1.6.0_20"
VER=1.6

if ! [ -d classes ]; then
echo Creating classes dir
mkdir classes
fi

echo Compiling...

cd src
"$JH\bin\javac" -nowarn -g -d ../classes -J-Xmx512m -classpath ../rt -source $VER -target $VER @../to_compile.txt 2>../error.log

echo Creating jar...

cd ../classes
"$JH\bin\jar" -cf ../rt-dbg.jar *

echo Done.


* This source code was highlighted with Source Code Highlighter .


(the script was tested on MSYS ).

As a result, if everything goes well (check error.log at the very end, there should only be warning'i), you will get the rt-dbg.jar file in the same directory.

Then, to make java use classes from this assembly, you need to run it with the key

-Xbootclasspath/p:D:/rt_debug/rt-dbg.jar

The links above say that you can throw in the endosed directory of your Java installation, but this path did not work for me.

The above code can be downloaded from the link .
UPD. rt-dbg.jar (17 mb)

Source: https://habr.com/ru/post/97262/


All Articles