Why do we use rt.jar in a java project?

前端 未结 9 1866
南方客
南方客 2020-12-12 14:32

What is the necessity of rt.jar ??

9条回答
  •  失恋的感觉
    2020-12-12 14:57

    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

提交回复
热议问题