Friday, December 01, 2006

Minimum "rt.jar" for Hello World

Here's a list of classes that are needed to run a Java hello world program.
I find this list using java -verbose (motivated by this post).

== listfile.txt ==
/java/io/BufferedInputStream.class
/java/io/BufferedOutputStream.class
/java/io/BufferedWriter.class
/java/io/Closeable.class
/java/io/DataInput.class
/java/io/DataInputStream.class
/java/io/ExpiringCache.class
/java/io/ExpiringCache$1.class
/java/io/ExpiringCache$Entry.class
/java/io/File.class
/java/io/FileDescriptor.class
/java/io/FileInputStream.class
/java/io/FileOutputStream.class
/java/io/FilePermission.class
/java/io/FilePermission$1.class
/java/io/FilePermissionCollection.class
/java/io/FileSystem.class
/java/io/FilterInputStream.class
/java/io/FilterOutputStream.class
/java/io/Flushable.class
/java/io/InputStream.class
/java/io/ObjectStreamClass.class
/java/io/ObjectStreamField.class
/java/io/OutputStream.class
/java/io/OutputStreamWriter.class
/java/io/PrintStream.class
/java/io/Serializable.class
/java/io/Win32FileSystem.class
/java/io/WinNTFileSystem.class
/java/io/Writer.class
/java/lang/AbstractStringBuilder.class
/java/lang/Appendable.class
/java/lang/ArithmeticException.class
/java/lang/ArrayStoreException.class
/java/lang/Boolean.class
/java/lang/Byte.class
/java/lang/CharSequence.class
/java/lang/Character.class
/java/lang/CharacterDataLatin1.class
/java/lang/Class.class
/java/lang/Class$1.class
/java/lang/Class$3.class
/java/lang/ClassCastException.class
/java/lang/ClassLoader.class
/java/lang/ClassLoader$3.class
/java/lang/ClassLoader$NativeLibrary.class
/java/lang/ClassNotFoundException.class
/java/lang/Cloneable.class
/java/lang/Comparable.class
/java/lang/Compiler.class
/java/lang/Compiler$1.class
/java/lang/Double.class
/java/lang/Error.class
/java/lang/Exception.class
/java/lang/Float.class
/java/lang/IncompatibleClassChangeError.class
/java/lang/Integer.class
/java/lang/Iterable.class
/java/lang/LinkageError.class
/java/lang/Long.class
/java/lang/Math.class
/java/lang/NoClassDefFoundError.class
/java/lang/NoSuchMethodError.class
/java/lang/NullPointerException.class
/java/lang/Number.class
/java/lang/Object.class
/java/lang/OutOfMemoryError.class
/java/lang/Readable.class
/java/lang/Runnable.class
/java/lang/Runtime.class
/java/lang/RuntimeException.class
/java/lang/RuntimePermission.class
/java/lang/Short.class
/java/lang/Shutdown.class
/java/lang/Shutdown$Lock.class
/java/lang/StackOverflowError.class
/java/lang/StackTraceElement.class
/java/lang/StrictMath.class
/java/lang/String.class
/java/lang/String$CaseInsensitiveComparator.class
/java/lang/StringBuffer.class
/java/lang/StringBuilder.class
/java/lang/StringCoding.class
/java/lang/StringCoding$CharsetSD.class
/java/lang/StringCoding$CharsetSE.class
/java/lang/StringCoding$StringDecoder.class
/java/lang/StringCoding$StringEncoder.class
/java/lang/System.class
/java/lang/System$2.class
/java/lang/SystemClassLoaderAction.class
/java/lang/Terminator.class
/java/lang/Terminator$1.class
/java/lang/Thread.class
/java/lang/Thread$UncaughtExceptionHandler.class
/java/lang/ThreadDeath.class
/java/lang/ThreadGroup.class
/java/lang/ThreadLocal.class
/java/lang/ThreadLocal$ThreadLocalMap.class
/java/lang/ThreadLocal$ThreadLocalMap$Entry.class
/java/lang/Throwable.class
/java/lang/VirtualMachineError.class
/java/lang/annotation/Annotation.class
/java/lang/management/MemoryUsage.class
/java/lang/ref/FinalReference.class
/java/lang/ref/Finalizer.class
/java/lang/ref/Finalizer$FinalizerThread.class
/java/lang/ref/PhantomReference.class
/java/lang/ref/Reference.class
/java/lang/ref/Reference$Lock.class
/java/lang/ref/Reference$ReferenceHandler.class
/java/lang/ref/ReferenceQueue.class
/java/lang/ref/ReferenceQueue$Lock.class
/java/lang/ref/ReferenceQueue$Null.class
/java/lang/ref/SoftReference.class
/java/lang/ref/WeakReference.class
/java/lang/reflect/AccessibleObject.class
/java/lang/reflect/AnnotatedElement.class
/java/lang/reflect/Constructor.class
/java/lang/reflect/Field.class
/java/lang/reflect/GenericDeclaration.class
/java/lang/reflect/Member.class
/java/lang/reflect/Method.class
/java/lang/reflect/Modifier.class
/java/lang/reflect/ReflectAccess.class
/java/lang/reflect/ReflectPermission.class
/java/lang/reflect/Type.class
/java/net/ContentHandler.class
/java/net/Parts.class
/java/net/URL.class
/java/net/URLClassLoader.class
/java/net/URLClassLoader$1.class
/java/net/URLConnection.class
/java/net/URLStreamHandler.class
/java/net/URLStreamHandlerFactory.class
/java/net/UnknownContentHandler.class
/java/nio/Bits.class
/java/nio/Buffer.class
/java/nio/ByteBuffer.class
/java/nio/ByteOrder.class
/java/nio/CharBuffer.class
/java/nio/HeapByteBuffer.class
/java/nio/HeapCharBuffer.class
/java/nio/charset/Charset.class
/java/nio/charset/Charset$3.class
/java/nio/charset/CharsetDecoder.class
/java/nio/charset/CharsetEncoder.class
/java/nio/charset/CoderResult.class
/java/nio/charset/CoderResult$1.class
/java/nio/charset/CoderResult$2.class
/java/nio/charset/CoderResult$Cache.class
/java/nio/charset/CodingErrorAction.class
/java/nio/charset/spi/CharsetProvider.class
/java/security/AccessControlContext.class
/java/security/AccessController.class
/java/security/AllPermission.class
/java/security/BasicPermission.class
/java/security/BasicPermissionCollection.class
/java/security/CodeSource.class
/java/security/Guard.class
/java/security/Permission.class
/java/security/PermissionCollection.class
/java/security/Permissions.class
/java/security/Principal.class
/java/security/PrivilegedAction.class
/java/security/PrivilegedActionException.class
/java/security/PrivilegedExceptionAction.class
/java/security/ProtectionDomain.class
/java/security/SecureClassLoader.class
/java/security/UnresolvedPermission.class
/java/security/cert/Certificate.class
/java/util/AbstractCollection.class
/java/util/AbstractList.class
/java/util/AbstractMap.class
/java/util/AbstractSet.class
/java/util/ArrayList.class
/java/util/BitSet.class
/java/util/Collection.class
/java/util/Collections.class
/java/util/Collections$EmptyList.class
/java/util/Collections$EmptyMap.class
/java/util/Collections$EmptySet.class
/java/util/Collections$ReverseComparator.class
/java/util/Collections$SynchronizedMap.class
/java/util/Comparator.class
/java/util/Dictionary.class
/java/util/Enumeration.class
/java/util/HashMap.class
/java/util/HashMap$Entry.class
/java/util/HashSet.class
/java/util/Hashtable.class
/java/util/Hashtable$EmptyEnumerator.class
/java/util/Hashtable$EmptyIterator.class
/java/util/Hashtable$Entry.class
/java/util/Iterator.class
/java/util/LinkedHashMap.class
/java/util/LinkedHashMap$Entry.class
/java/util/List.class
/java/util/Locale.class
/java/util/Map.class
/java/util/Map$Entry.class
/java/util/Properties.class
/java/util/Random.class
/java/util/RandomAccess.class
/java/util/Set.class
/java/util/SortedMap.class
/java/util/Stack.class
/java/util/StringTokenizer.class
/java/util/TreeMap.class
/java/util/TreeMap$Entry.class
/java/util/Vector.class
/java/util/concurrent/atomic/AtomicLong.class
/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.class
/java/util/concurrent/atomic/AtomicReferenceFieldUpdater$AtomicReferenceFieldUpdaterImpl.class
/java/util/jar/JarEntry.class
/java/util/jar/JarFile.class
/java/util/jar/JarFile$JarFileEntry.class
/java/util/jar/JavaUtilJarAccessImpl.class
/java/util/zip/Inflater.class
/java/util/zip/InflaterInputStream.class
/java/util/zip/ZipConstants.class
/java/util/zip/ZipEntry.class
/java/util/zip/ZipFile.class
/java/util/zip/ZipFile$2.class
/java/util/zip/ZipFile$ZipFileInputStream.class
/sun/io/Converters.class
/sun/misc/ASCIICaseInsensitiveComparator.class
/sun/misc/AtomicLong.class
/sun/misc/AtomicLongCSImpl.class
/sun/misc/ExtensionDependency.class
/sun/misc/FileURLMapper.class
/sun/misc/JarIndex.class
/sun/misc/JavaLangAccess.class
/sun/misc/JavaUtilJarAccess.class
/sun/misc/Launcher.class
/sun/misc/Launcher$AppClassLoader.class
/sun/misc/Launcher$AppClassLoader$1.class
/sun/misc/Launcher$ExtClassLoader.class
/sun/misc/Launcher$ExtClassLoader$1.class
/sun/misc/Launcher$Factory.class
/sun/misc/NativeSignalHandler.class
/sun/misc/Resource.class
/sun/misc/SharedSecrets.class
/sun/misc/Signal.class
/sun/misc/SignalHandler.class
/sun/misc/SoftCache.class
/sun/misc/URLClassPath.class
/sun/misc/URLClassPath$3.class
/sun/misc/URLClassPath$FileLoader.class
/sun/misc/URLClassPath$FileLoader$1.class
/sun/misc/URLClassPath$JarLoader.class
/sun/misc/URLClassPath$Loader.class
/sun/misc/Unsafe.class
/sun/misc/VM.class
/sun/misc/Version.class
/sun/net/www/MessageHeader.class
/sun/net/www/ParseUtil.class
/sun/net/www/URLConnection.class
/sun/net/www/protocol/file/FileURLConnection.class
/sun/net/www/protocol/file/Handler.class
/sun/net/www/protocol/jar/Handler.class
/sun/nio/ByteBuffered.class
/sun/nio/cs/AbstractCharsetProvider.class
/sun/nio/cs/FastCharsetProvider.class
/sun/nio/cs/HistoricallyNamedCharset.class
/sun/nio/cs/MS1252.class
/sun/nio/cs/MS1252$Decoder.class
/sun/nio/cs/MS1252$Encoder.class
/sun/nio/cs/SingleByteDecoder.class
/sun/nio/cs/SingleByteEncoder.class
/sun/nio/cs/StandardCharsets.class
/sun/nio/cs/StandardCharsets$Aliases.class
/sun/nio/cs/StandardCharsets$Cache.class
/sun/nio/cs/StandardCharsets$Classes.class
/sun/nio/cs/StreamEncoder.class
/sun/nio/cs/StreamEncoder$CharsetSE.class
/sun/nio/cs/Surrogate.class
/sun/nio/cs/Surrogate$Parser.class
/sun/nio/cs/ext/ExtendedCharsets.class
/sun/nio/cs/ext/MS874.class
/sun/nio/cs/ext/MS874$Decoder.class
/sun/nio/cs/ext/MS874$Encoder.class
/sun/reflect/ConstantPool.class
/sun/reflect/ConstructorAccessor.class
/sun/reflect/ConstructorAccessorImpl.class
/sun/reflect/DelegatingClassLoader.class
/sun/reflect/DelegatingConstructorAccessorImpl.class
/sun/reflect/LangReflectAccess.class
/sun/reflect/MagicAccessorImpl.class
/sun/reflect/MethodAccessor.class
/sun/reflect/MethodAccessorImpl.class
/sun/reflect/NativeConstructorAccessorImpl.class
/sun/reflect/Reflection.class
/sun/reflect/ReflectionFactory.class
/sun/reflect/ReflectionFactory$1.class
/sun/reflect/ReflectionFactory$GetReflectionFactoryAction.class
/sun/reflect/misc/ReflectUtil.class
/sun/security/action/GetPropertyAction.class
/sun/security/util/Debug.class
/sun/util/PreHashedMap.class



The following is a command for 7z to strip down the rt.jar (from 37,043 Kb to 1,806 Kb).

7z.exe d -r -x@listfile.txt rt.jar *.class



I tested with JRE 1.5_08 on Windows XP.

2 comments:

Prach Pongpanich said...

i never seen you in msn ?

Anonymous said...

How can we reduce rt.jar to only classes required by my java application?

Radek