Why do we use rt.jar in a java project?
rt = Run Time
It contains all the java runtime libraries. (Essential)
Cross compilation is one case where you have to explicitly use it.
E.g., if you are on Java 8, and want to compile Java 7 while rejecting Java 8 extensions. So you could try:
javac -source 1.7 Main.java
But then javac
will say: warning: [options] bootstrap class path not set in conjunction with -source 1.7
, because it might generate error co compile against a different version of the JCL.
So you would need to set rt.jar
with:
javac -source 1.7 -bootclasspath /usr/lib/jvm/java-7-oracle/jre/lib/rt.jar Main.java
This was asked at: warning: [options] bootstrap class path not set in conjunction with -source 1.5
It contains all the classes provided in the Java Runtime Environment.
If you don't have it on your classpath you will not have access to any of those classes you need to use like java.lang.String or java.io.File.