I have used servlet and jsp, but I only import java basis jar.
Which is javaEE jar?
HttpServlet depends on Tomcat's servlet-api.jar, what is the relationship between javaEE and tomcat? This is my structure in the project
Thank you!
I have used servlet and jsp, but I only import java basis jar.
Which is javaEE jar?
HttpServlet depends on Tomcat's servlet-api.jar, what is the relationship between javaEE and tomcat? This is my structure in the project
Thank you!
1) rt.jar stands for runtime and contains all of the compiled class files for the core Java Runtime environment.
2) You must include rt.jar in your classpath, otherwise you don't have access to core classes e.g. java.lang.String, java.lang.Thread, java.util.ArrayList or java.io.InputStream and all other classes from Java API. You can actually see what is inside rt.jar by opening it by using WinRAR or WinZip client. You can see that it not only contains all Java API but also internal classes specified in com package.
3) In windows, rt.jar will always reside under $JAVA_HOME/jre/lib, where $JAVA_HOME refers to JDK installation directory. Even if you don't install JDK and just install JRE, you will see it in exactly same location, you won't find rt.jar inside $JAVA_HOME/lib directory. BTW, On MacOSX it is called classes.jar and located under /System/Library/Frameworks//Classes directory. In following screenshot you can see that rt.jar is inside JRE's lib directory in Windows 8.
4) The rt.jar is where all the Java packages reside. For example, if a class file need to refer a class from java.util.concurrent package e.g. ConcurrentHashMap, then the JVM will look for it inside the rt.jar, thus enabling it to run correctly.
5) One more question Java programmer ask is, where can I find source code for classes included in rt.jar? well, if you have installed JDK, not JRE then you can find all sources inside $JAVA_HOME/src.zip file. BTW, sun.* sources are also included in src.zip but that is proprietary closed source Oracle code. I also suggest you to include this JAR file in your Eclipse, so that you can view source code of any JDK class by just typing Ctrl + T and name of the class, rest will be taken care by Eclipse's Java type search functionality.
6) One of the most important thing to know about rt.jar is that all the classes in this JAR file is known to JVM, which means JVM doesn't do all the checks it does while loading any other JAR from any other location. This is done due to various performance reason and that's why these classes are loaded by bootstrap or primodial class loaders. Don't try to include your class files in rt.jar, as its not advised by Java. It also compromise with any security.
7) If you are curious about different binary and JAR files used by Java platform, then look into this diagram. You can see that JDK has three main folders bin, lib and jre. bin directory contains all binary executable e.g. java.exe to run Java program, javac.exe to compile Java program etc. lib contains tools.jar and dt.jar. jre folder again contain bin and lib directory. It's in this lib directory rt.jar reside. By the way for complete explanation of what each of these file and folder does, checkout Oracle official pages. They are very comprehensive and descriptive.
That's all about rt.jar file in Java. Now you know what is the purpose of rt.jar and why you should not mess with it. You can find this JAR file inside $JAVA_HOME/jre/lib directory and I encourage you to look it by yourself.