注册 | 登录 忘记密码? 51cto首页 | 博客 | 论坛 | 招聘
热点文章 模拟Linux客户端远程登陆L..
 帮助

jdk源码编译释疑


2006-04-29 16:51:00
 标签:   [推送到技术圈]

Those classes are not in rt.jar and are probably old files that were never deleted.

You will need to :

1) delete any java files that are not in rt.jar

2) run javac with the following classpath:
C:\java\jdk1.4\lib\dt.jar;C:\java\jdk1.4\lib\tools.jar;C:\java\jdk1.4\lib\htmlconverter.jar

3) copy any classes from rt.jar that you do not have source for
Notably sun.* and com.sun.* classes

Then just jar it up and you should be in business.

The following script automates all that on linux


#!/bin/sh

# Change these four paths as required

# Base dir
JAVA_HOME=/usr/java/jdk1.4.2

# Where src.zip was extracted
JAVA_SOURCE=$JAVA_HOME/src

# Where rt.jar was extracted
RT_CLASSES=$JAVA_HOME/rt

# Where to put the compiled classes
OUT_DIR=$JAVA_HOME/classes


# These are the required options for javac, do not change
OPTIONS="-g -nowarn -sourcepath . -d $OUT_DIR -source 1.4 -target 1.4"
CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/htmlconverter.jar


# Loop through each java file in the source dir
cd $JAVA_SOURCE
/usr/bin/find . -iname "*.java" | while read JAVA; do

echo $JAVA

# Is this file part of rt.jar, or is it an obsolete source file
# eg com/sun/corba/se/internal/Interceptors/ThreadCurrentStack.java

CLASS=$(echo $JAVA | sed "s/\.java/\.class/g")
if [ -f ${RT_CLASSES}/${CLASS} ]; then
  # Has this file already been compiled
  if [ -f ${OUT_DIR}/${CLASS} ]; then
    echo Already compiled.
  else
    javac $OPTIONS $JAVA
  fi
else
  echo Obsolete source file.
fi
done


# Now check for any classes that are in rt.jar but not src.zip
cd $RT_CLASSES
/usr/bin/find . -iname "*.class" | while read CLASS; do
if [ ! -f ${OUT_DIR}/${CLASS} ]; then
  echo Not found : $CLASS
fi
done


That script can also be run in windows using cygwin (www.cygwin.com)

Just change the line


    javac $OPTIONS $JAVA


to


    ${JAVA_HOME}/bin/javac $OPTIONS $JAVA


Here is a revised script that will run on linux, solaris and windows (cygwin)

In linux/solaris set JAVA_HOME to something like /usr/java/jdk1.4.2
In windows set JAVA_HOME to something like C:/java/jdk1.4.2

#!/bin/sh

# Change these four paths as required

# Base dir
JAVA_HOME=/usr/java/jdk1.4.2

# Where src.zip was extracted
JAVA_SOURCE=$JAVA_HOME/src

# Where rt.jar was extracted
RT_CLASSES=$JAVA_HOME/rt

# Where to put the compiled classes
OUT_DIR=$JAVA_HOME/classes


# These are the required options for javac, do not change
OPTIONS="-g -nowarn -sourcepath . -d $OUT_DIR -source 1.4 -target 1.4"
case `uname` in
CYGWIN*)
SEP=";";;
*)
SEP=":";;
esac
CLASSPATH=$JAVA_HOME/lib/dt.jar$SEP$JAVA_HOME/lib/tools.jar$SEP$JAVA_HOME/lib/htmlconverter.jar
JAVAC_HOME=$JAVA_HOME/bin


# Loop through each java file in the source dir
cd $JAVA_SOURCE
/usr/bin/find . -name "*.java" | while read JAVA; do

echo $JAVA

# Is this file part of rt.jar, or is it an obsolete source file
# eg com/sun/corba/se/internal/Interceptors/ThreadCurrentStack.java

CLASS=`echo $JAVA | sed "s/\.java/\.class/g"`
if [ -f ${RT_CLASSES}/${CLASS} ]; then
  # Has this file already been compiled
  if [ -f ${OUT_DIR}/${CLASS} ]; then
    echo Already compiled.
  else
    ${JAVAC_HOME}/javac -classpath $CLASSPATH $OPTIONS $JAVA
  fi
else
  echo Obsolete source file.
fi
done


# Now check for any files that are in rt.jar but not src.zip
cd $RT_CLASSES
/usr/bin/find . -type f | while read CLASS; do
if [ ! -f ${OUT_DIR}/${CLASS} ]; then
  echo Not found : $CLASS
  # Uncomment this once the script has been run and all classes have successfully compiled
#   cp --parents $CLASS $OUT_DIR
fi
done




    文章评论
 
 

发表评论

昵   称:
验证码:  点击图片可刷新验证码  博客过2级,无需填写验证码
内   容: