1,默认eclipse有自己的classpath的路径并不是环境变量中配置的classpah.

2,eclipse的classpath每个项目不同,一般是在工作区的当前项目的class下。

2.1,可以通过下面代码查看:

 System.out.println(System.getProperty("java.class.path"));  

2.2也可以通过eclipse菜单查看:

Run→Run Configures...在classpath选项卡下就会发现,Eclipse默认是没有导入系统的CLASSPATH路径的

3,可以通过eclipse添加自己指定的classpath路径:

1,在工程上右击→Properties-java build path,在Libraries选项卡下,Add External Class Folder...,选择自己需要导入的类文件夹
2,完成之后你会在工程下面看到Referenced Libraries

4,修改classpah的几种方式:

,当然就是直接在环境变量设置
,在dos中使用set classpath=路径
3,在dos使用java -cp 路径
(cp是classpath的缩写,dos环境设置的只是临时的,窗口关闭也就失效了)
,在代码中设置System.setProperty(“java.library.path”,“classpath路径”)

但是在代码修改有个问题:

那就是classpath对应的是系统类加载器(AppClassLoader),那就是在代码运行前系统类加载器已经实例化,也就是classpaht已经被确定了。
那么指定的路径可能并不会起作用,路径下的类会出现找不到的异常。

虽然修改了classpath的值,但是类加载器已经启动了,再修改其classpath的值已经对那个已经启动的类加载器或者说是jvm不起作用了。

使用java代码动态修改classpath

google关键词:“setting the classpath at runtime” 在此我贴出一些解释
)The classloader represents (part of) a namespace, and two otherwise identical classes loaded by different classloaders are not “equal”. Which means there are a few dangers lurking in classloading, notably singletons suddenly not being so single anymore as well as casts failing unexpectedly.
)Classloaders (should) work on a pattern of delegating to the “parent” loader before attempting anything themselves (see above).
)Class loading and linking are two distinct steps (even though example implementations of a classloader such as may be found in blog posts/online Java articles, will combine the two into one for simplicity) Therefore you should not assume that if a parent loader has loaded a class it has also loaded all dependencies …
)All this means there is a problem if class A loaded by loader A references a class B which neither loader A nor any of its parents can load: class A may load just fine in loader A but at the point of use it fails because loader A cannot fully resolve (link) it.
)And you should make sure that your classloader loads classes in a synchronized manner otherwise the issues hinted at in step # can leap from duplicates due to classloaders to duplicates from multiple threads using the same classloader as well…

eclipse的classpath(build path)和classpaht几种设置的方式的更多相关文章

  1. 大杂烩 Classpath / Build path / Debug关联源码 / JDK&JRE区别

    Classpath的理解及其使用方式 原文地址:http://blog.csdn.net/wk1134314305/article/details/77940147?from=bdhd_site 摘要 ...

  2. eclipse中Build Path-Add to Build Path相应到androidstudio的设置

    有些时候并不须要加入lib库进行编译,比如在使用xposed的jar包时,仅仅须要在eclipse里Build Path-Add to Build Path就可以,假设作为lib库加入进去反而会出现异 ...

  3. Eclipse中Java build path的使用

    1.Eclipse中,工程属性的Java Build Path的Library标签页下,有如下几个按钮:Add Jars...添加JAR包,是指本Eclipse当前包含的工程中的,在工程列表下选取即可 ...

  4. Eclipse下Java Build Path下Libraies中添加 Maven dependencies 失败解决方案

    当maven 仓库有jar时,tomcat生成时总是报javaclassno..........无这个文件:用一下方法 转载:http://bugyun.iteye.com/blog/2311848 ...

  5. eclipse 右键没有Build Path

    如果Project Explorer右键没有build pathWindow ->show view 选择package explorer 参考https://blog.csdn.net/cod ...

  6. eclipse 工程没有build path

    项目的.project文件添加: <buildSpec><buildCommand><name>org.eclipse.jdt.core.javabuilder&l ...

  7. eclipse中java build path下 allow output folders for source folders 无法勾选,该如何解决 eclipse中java build path下 allow output folders for source folders 无法勾选,

    在创建maven工程时,在设置output folders时,总是勾选以后,老是自动恢复到原来的状态,对比其他的maven的工程发现是在创建maven时候选择的项目为pom,而不是war或者jar,将 ...

  8. Eclipse中的build path详解

    http://blog.csdn.net/qqqqqq654/article/details/53043742

  9. java环境配置classpath和path变量的作用及设置方法

    1.path:指定cmd中命令执行文件所在的路径.比如javac.java两个可执行文件在jdk的bin目录下,如果path值含有这个bin目录,在cmd下执行这两个命令的时候就会到path指定的目录 ...

随机推荐

  1. [转] 移动平台Html5的viewport使用经验

    转自:http://blog.csdn.net/wuruixn/article/details/8591989 问题描述 web页面采用html5技术实现,在系统登录页面中使用frameset.fra ...

  2. C语言文件实现学生成绩管理

    C语言实现学生成绩管理 项目简介 用C语言的链表及文件操作实现学生成绩的管理,实现主要的添加.修改.删除.查询的主要功能,并在程序关闭时将数据存储在二进制的文件中并加密.下一次打开程序,先解密二进制文 ...

  3. 59. Spiral Matrix II (Array)

    Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. For ...

  4. react-navigation 3.x版本的安装以及react-native-gesture-handler配置

    一.安装依赖,使用npm或yarn命令,3.x版本必须安装react-native-gesture-handler react-navigation react-native-gesture-hand ...

  5. sql判断表是否已经存在

    if (object_id(N'td_VipExchangeCodeInfo',N'U') is not null)print '存在'else print '不存在'

  6. Castle ActiveRecord学习(八)事务

    代码: public void UpdateThemeInfo(int id) { //事务 using (TransactionScope ctran = new TransactionScope( ...

  7. 怎样application不被第三方应用杀掉--Android

    方法: 对于放在/system/app下的应用,需要在其Manifest.xml文件中设置persistent属性,如应用程序'Phone'的AndroidManifest.xml文件: <ap ...

  8. 现在有很多第三方的SDK来做直播,那么我们改选择哪一种?

    现在大部分的都会借助第三方的直播技术,这样可以保证直播的质量,趣拍直播就很不错,SDK很好集成,芒果直播也在用.下面来分析一下趣拍直播的一些心得. 如何快速搭建一个完整的手机直播系统 在这个直播如火如 ...

  9. [GO]go使用etcd

    package main import ( "go.etcd.io/etcd/clientv3" //笔者在使用clientv3的时间曾经使用过github.com/coreos/ ...

  10. tpshop使用中遇到的问题

    1.短信配置里:商家发货时是否给客户发短信  配置了 开启   如果购买者个人资料里的电话没填写,商家点击发货时, 程序会挂掉 解决方法:修改application\common\logic\SmsL ...