Back

Classpath and jar in Java

classpath and jar.

What is Classpath?

  • Classpath represents the path where JVM can find corresponding classes.

    • source file name: xxx.java –> xxx.class

    • In Windows:

      • C:\work\project1\bin;C:\shared;"D:\My Documents\project1\bin"
        
    • In linux:

      • /usr/shared:/usr/local/bin:/home/liaoxuefeng/bin
        
    • . represents current path

How to Set Classpath?

  • In Windows:

    • java -cp .;C:\work\project1\bin;C:\shared abc.xyz.Hello
      
  • In linux:

    • java -cp .:/usr/shared:/usr/local/bin:/home/liaoxuefeng/bin
      

What is jar?

  • It is a zip format of the compressed file.

  • Manually Create:

    • compress to zip format –> modify the postfix to jar
  • Use Tools:

    • Maven
comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy