Open In App

How is CompileTime classpath different from RunTime classpath in Java?

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.




<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?


Article Tags :