java: lib & classpath

classpath, is the path to search for third-part or user-defined classes,

refer to:
* linux
    docs.oracle.com/javase/6/docs/technotes/tools/solaris/classpath.html
    docs.oracle.com/javase/6/docs/technotes/guides/extensions/extensions.html
    docs.oracle.com/javase/7/docs/technotes/tools/solaris/jdkfiles.html
* windows
    docs.oracle.com/javase/6/docs/technotes/tools/windows/classpath.html
*

------
3 level of jars

include:
* java platform classes (bootstrap)
    location:
        jre_home/lib/
            rt.jar
            ..
    this will be searched automatically, load by bootstrap classloader,
* java extension
    location:
        jre_home/lib/ext/
    this will be searched automatically, load by extension classloader,
* third-party & user-defined
    this need to specify in classpath, load by system classloader,
*

search order:
    java platform classes -> java extension -> third-party & user-defined,

------
set classpath

2 ways to set:
* set CLASSPATH environment
* use -cp option
*

default value:
    classpath default to current dir,

override:
    both of them will override the default classpath,
    so add "." to include current dir, and add "$CLASSPATH" as prefix to include the original classpath,

search order:
    the search order of classpath, is the same as you specified in classpath,

------
classpath format

format:
    linux:
        path_1:path_2:..:path_N
    windows:
        path_1;path_2;..;path_N

path:
    each path could be jar/zip/dir, '.' means current path,
    the dir or root dir included by jar/zip, should include:
    * the top package folder, if class has package
    * .class file, if class has no package

wildcard:
    '*', used it at end of a path, after separator '/', it equals to include all files with extension '.jar' or '.JAR' in that folder,
    '*' can't be used in other format,
    e.g.
        # this will include all jars under "/tmp/lib"
        "/tmp/lib/*"

------
tools.jar & dt.jar

under jdk_home/lib, there are some jars, they are not part of java platform, but are useful tools,
if want to use them, need to include in classpath,

jars:
* tools.bar
    non-core classes for support of the tools and utilities in the JDK
* dt.jar
     the DesignTime archive of BeanInfo files that tell IDE how to display the Java components and how to let the developer customize them for an application,
*

------
e.g.

* config classpath - linux - eric.sh
    CLASSPATH=.:$JAVA_HOME/lib/*
* execute command by add additional path to configured classpath - linux
    java -cp $CLASSPATH:/mnt/star/workspace/java_workplace hello.Test
*
* set classpath via command temporary - linux shell
    # include a single jar, base on original classpath,
    export CLASSPATH=$CLASSPATH:/tmp/test.jar
    # include all jars under specified folder, base on original classpath,
    export CLASSPATH=$CLASSPATH:/tmp/lucene_demo/lib/*
*

------

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值