Java Classpath

  1. Java Classpath

  2. This Java tutorial is to help Java beginners add a Java class or jar files to the Java classpath. 

    Java-Classpath

    ClassNotFoundException is thrown when the referred Java class is not found by the Java runtime. 

    Use echo %CLASSPATH% to know the current classpath that is set.


  3. Following are the different ways to add a Java class file or jar file to the Java classpath,

  4. java.lang.ClassNotFoundException  is one of the frequently faced exceptions for a Java beginner.

  5. Classpath argument in java tool

  6. Set classpath to a jar in current folder:

    java -classpath "mysql-connector-java-5.1.19-bin.jar" MyJavaClassName

    Set classpath to multiple jar files:

    java -cp \tools.jar;.; \utils.jar MyJavaClassName

    Set classpath to multiple jar files in same folder:

    java -cp .; \*; MyJavaClassName

    Set classpath to class file in current folder:

    java -cp .; MyJavaClassName

    Separator ; is for windows. : is for Unix systems.

  7. Use “ext” location in Java installation directory

    Copy required jar files to ext folder in the Java jdk installation:C:\Program Files\Java\jdk1.8.0\jre\lib\ext

  8. Use SystemRoot (From Java SE 6)

    Unlike the above, Jars placed in SystemRoot is available for all JDKs:

    %SystemRoot%\Sun\Java\lib\ext

  9. Add Jar file to CLASSPATH environment variable

    CLASSPATH environment variable can be set in multiple ways and it depends on the OS used. In Windows, it can be set using the command-line tool. When set using command-line tool, it will live until that command-line session is closed. Alternately, it can be set from System –> Properties.

    set CLASSPATH = ;

    Use separator (; for windows or : for Unix systems) to add multiple entries.

  10. Add to Jar Manifest

    When a Jar file is dependent on other Jar files, then the dependent jar files list can be added to the required Jar file’s manifest entry.

    jar cfm helloWorld.jar Manifest.txt com/javapapers/*.class

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值