myeclipse中的classpath

来源:互联网 发布:java 支付宝订单查询 编辑:程序博客网 时间:2024/05/16 17:04

myeclipse中的classpath是一个很重要的问题

myeclipse的在查找的时候都是按照其查找,而且myeclipse有一个专门的文件来保存classpath的信息,这也是别人的项目拷贝的时候需要的一个重要文件,不然这个项目要导入到自己的myeclipse中就会发生错误,此时就只能是手工来编写这个文件


myeclipse的classpath文件就是项目根目录下的“.classpath”文件,其格式如下:

<?xml version="1.0" encoding="UTF-8"?><classpath><classpathentry kind="src" path="src"/><classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/><classpathentry kind="con" path="melibrary.com.genuitec.eclipse.j2eedt.core.MYECLIPSE_JAVAEE_5_CONTAINER"/><classpathentry kind="lib" path="WebRoot/WEB-INF/lib/bsf-2.3.0.jar"/><classpathentry kind="lib" path="WebRoot/WEB-INF/lib/commons-beanutils-1.7.0.jar"/><classpathentry kind="lib" path="WebRoot/WEB-INF/lib/commons-chain-1.1.jar"/><classpathentry kind="lib" path="WebRoot/WEB-INF/lib/commons-digester-1.8.jar"/><classpathentry kind="lib" path="WebRoot/WEB-INF/lib/commons-fileupload-1.1.1.jar"/><classpathentry kind="lib" path="WebRoot/WEB-INF/lib/commons-io-1.1.jar"/><classpathentry kind="lib" path="WebRoot/WEB-INF/lib/commons-logging-1.0.4.jar"/><classpathentry kind="lib" path="WebRoot/WEB-INF/lib/commons-validator-1.3.1.jar"/><classpathentry kind="lib" path="WebRoot/WEB-INF/lib/oro-2.0.8.jar"/><classpathentry kind="lib" path="WebRoot/WEB-INF/lib/struts-core-1.3.8.jar"/><classpathentry kind="lib" path="WebRoot/WEB-INF/lib/struts-el-1.3.8.jar"/><classpathentry kind="lib" path="WebRoot/WEB-INF/lib/struts-extras-1.3.8.jar"/><classpathentry kind="lib" path="WebRoot/WEB-INF/lib/struts-faces-1.3.8.jar"/><classpathentry kind="lib" path="WebRoot/WEB-INF/lib/struts-mailreader-dao-1.3.8.jar"/><classpathentry kind="lib" path="WebRoot/WEB-INF/lib/struts-scripting-1.3.8.jar"/><classpathentry kind="lib" path="WebRoot/WEB-INF/lib/struts-taglib-1.3.8.jar"/><classpathentry kind="lib" path="WebRoot/WEB-INF/lib/struts-tiles-1.3.8.jar"/><classpathentry kind="output" path="WebRoot/WEB-INF/classes"/></classpath>

第一句

<?xml version="1.0" encoding="UTF-8"?>

这是表明使用的XML的版本,以及使用的编码

<classpath>... ...</classpath>

    这个标签中存放的便是classpath的信息,它一般包含以下五种形式:

     <classpathentry kind="src" path="src"/>    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>    <classpathentry kind="con" path="melibrary.com.genuitec.eclipse.j2eedt.core.MYECLIPSE_JAVAEE_5_CONTAINER"/>    <classpathentry kind="lib" path="WebRoot/WEB-INF/lib/bsf-2.3.0.jar"/>    
<classpathentry kind="output" path="WebRoot/WEB-INF/classes"/>

<classpath kind="src" path="src"> 对应的是source folder类型的目录,kind---表示这个classpath的类型,path表示在项目中的路径,path使用根目录的相对路径(相对.classpath文件本身的相对路径) ,myeclipse项目中的src本身就是一个source folder,所以它会自动写入这个文件中,如果自己手动建立了一个source folder,这个folder也会写入这个文件,形式就是以上形式eg.在项目基础上新建一个test的source folder,就会就会成为这样:
    <classpathentry kind="src" path="src"/>    <classpathentry kind="src" path="test"/>


<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>

这句是表示程序的运行环境 kind="con"---表示classpath的类型,con即是container,就是程序运行的容器,或者就说是运行环境也OK,它实际上是在Myeclipse最初的时候要配置installed JREs中指定(一般情况下我们指定的是JDK),但是这里实际使用的是JDK下的JRE中的jar包,就是JDK_HOME/jre/lib就是对应的这条语句

<classpathentry kind="con" path="melibrary.com.genuitec.eclipse.j2eedt.core.MYECLIPSE_JAVAEE_5_CONTAINER"/>


这句是kind="con"当然和上条一样,是表示运行时的容器,一般情况下是java web项目才会有,它是包含了J2EE服务器要使用到的一些jar包,这个目录中的jar包是其中最特殊的,那就是它不会在部署项目的时候部署到服务器上去,因为myeclipse认为这样的jar包是服务器应该有的,所以这里有时候会出现问题,就是开发的时候不出现问题,但是部署之后会出错,就是有的服务器有的jar包并没有提供,比如tomcat(因为tomcat并不是专业的web服务器,它只是一个轻量的web容器),这就要区分好开发环境和运行环境


<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/bsf-2.3.0.jar"/>

这条语句kind="lib",对应的是classpath中的库文件,path指定库文件的路径,同样是相对与项目根目录的相对路径


<classpathentry kind="output" path="WebRoot/WEB-INF/classes"/>

这条表示项目的输出目录,整个之前定义的classpath无论是kind='src",kind="con",kind="lib",在编译后都会进入到这个目录中来,在java web中也就是WebRoot/WEB-INF/classes。同样使用的path是相对项目根目录的相对路径(相对.classpath文件本身的相对路径),但是由于J2EE部分的是本身要求web 服务器本身要有那些jar包,所以那个例外不会进行拷贝


总结:

classpath是myeclipse重要文件,在进行相关的查找时候要用到

项目根目录下的".classpath“文件就是保存项目classpath的文件

文件中的
<classpath>... ...</classpath>之间保存各种classpath信息,kind表示类型,path表示路径,且使用的都是相对于”.classpath“或者说是项目根目录的相对路径

几种kind的含义:

kind=”src" ----对应source folder目录

kind="con"--项目的容器,一般当是java web项目的时候会有两个

kind="lib"---项目中使用到的库文件

kind='output"--输出目录,最终编译后相关文件的目标目录,myeclipse会自动完成相关的拷贝

最终对于myeclipse的classpath的管理都是通过这个文件实现!

	
				
		
原创粉丝点击