How is CompileTime classpath different from RunTime classpath in Java? Last Updated : 09 Aug, 2019 Comments Improve Suggest changes Like Article Like Report What is a Classpath? Classpath refers to the Path where all the classes/jars are available. What is Compile-time classpath? This classpath has all the classes/jars required to compile the application without any syntax error. Now we might think that our project compiled successfully so it will execute nicely. But this is not always true why because in some cases(explained below) to execute the project successfully you may need some other class/jars at runtime. That is why run-time classpath comes into the picture. What is Run-time classpath? Classpath that has all the classes/jars required to execute the application successfully. Setting classpath: Just add the dependencies in the pom.xml file will automatically add the jars in classpath. sample pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.softvision</groupId> <artifactId>SpringMVC</artifactId> <packaging>war</packaging> <version>1.0-SNAPSHOT</version> <name>SpringMVC Json Webapp</name> <url>http://maven.apache.org</url> <properties> <spring.version>3.2.2.RELEASE</spring.version> <jackson.version>1.9.10</jackson.version> <jdk.version>1.6</jdk.version> </properties> <dependencies> <!-- Spring 3 dependencies --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <!-- Jackson JSON Mapper --> <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-mapper-asl</artifactId> <version>${jackson.version}</version> </dependency> </dependencies> </project> Note: Classpath setting will be done by eclipse or any other IDE automatically. This can't be shown here. How is CompileTime classpath different from RunTime classpath? Case-1: Let's say we are developing a Spring-MVC web application to post the JSON data. So in order to achieve it, we need Jackson jar to map the JSON data to the DTO class. If we don't have this jar in the classpath then at the compile time we won't get any error but our application will not execute properly because it needs Jackson for data binding at the runtime that is not available. That is why we say compile-time and run-time classpath are different. Case-2: While developing servlet based application we need servlet-api.jar so we can use HttpServlet, HttpServletRequest, HttpServletResponse, etc while writing code and end up in no compilation error. At this point, we are using servlet-API that is just specification not the actual implementation of the servlet-API. Actually, the implementation is the JEE container that is required to run the servlet based application. So what I am trying to say that while running such an application the JEE container will provide the implementation classes at runtime to successfully run it without the JEE container application will not run. Comment More infoAdvertise with us Next Article How is CompileTime classpath different from RunTime classpath in Java? C Chirag Soni Follow Improve Article Tags : Misc Java java-basics Practice Tags : JavaMisc Similar Reads How to run java class file which is in different directory? In this article, we will learn about how to use other project's utilities, classes, and members. Before proceeding let's learn about some keywords. classpath Classpath is the location from where JVM starts execution of a program. Similar to the classic dynamic loading behavior, when executing Java p 6 min read Different Ways to Set a Classpath in Java Java Virtual Machine(JVM) uses classpath to locate the class files to execute the code. If your classpath is not set and the class file is not present in the same directory as your java file, then JVM will be unable to find the required class file, and it will throw an error (java.lang.ClassNotFound 3 min read How to Add JAR file to Classpath in Java? JAR is an abbreviation of JAVA Archive. It is used for aggregating multiple files into a single one, and it is present in a ZIP format. It can also be used as an archiving tool but the main intention to use this file for development is that the Java applets and their components(.class files) can be 4 min read Difference Between Path and ClassPath in Java The ClassPath is a parameter in the Java Virtual Machine(JVM) or the Java compiler that is used by a system or application ClassLoader to locate and load compiled Java bytecodes stored in the ".class" file. On the other hand, The Path is also an environment variable path that behaves as a mediator b 2 min read Difference between Compile-time and Run-time Polymorphism in Java The word polymorphism means having many forms. In simple words, we can define polymorphism as the ability of a message to be displayed in more than one form. In this article, we will see the difference between two types of polymorphisms, compile time and run time. Compile Time Polymorphism: Whenever 3 min read Like