- 浏览: 2081998 次
- 性别:
- 来自: 杭州
文章分类
最新评论
-
无心流泪wan:
private static final Log log = ...
log4j Category.callAppenders Block -
yjxa901:
博主好: http://www.java.net/down ...
jdk debug -
aptech406328627:
大神,请接收我的膜拜吧,纠结了两天的问题,就这么让你给解决了 ...
java.lang.reflect.MalformedParameterizedTypeException -
xukunddp:
谢谢1楼,我也遇到,搞定了
java.lang.reflect.MalformedParameterizedTypeException -
di1984HIT:
学习了!!!!
jvmstat hsperfdata java.io.tmpdir
经常遇到eclipse中jar依赖问题,每次都需要看eclipse生成的classpath文件,为了有个权威的说明,故找来了这个文件的格式说明(真不好找>_^),为了确保内容以后不丢失,我先放一份在blog里。
转载自:http://www.ibm.com/developerworks/opensource/tutorials/os-eclipse-classpath/section2.html
Simplify Eclipse classpaths using classpath containers
Introduction to classpath containers
Classpath containers are an effective way to organize project resources by grouping them under one logical classpath entry. Whether you realize it or not, you may have used a classpath container. The most recognized classpath container among Java developers is the JRE System Library. Every Java project has a JRE System Library in the classpath. Other notable classpath containers are the JUnit and Plug-in Dependencies containers included in the base Eclipse project, as well as the Web App Libraries container, which is part of the dynamic Web project type in the Web Tools Project (WTP). Before we start implementing our own classpath container, let's start by reviewing the different types of classpath entries.
Every Java project includes a .classpath file that defines the classpath of the project. This file is generally not edited by hand but created and modified by the JDT plug-in as the user changes the Java build path properties of a project. Each entry in the classpath has a kind
attribute and a path
attribute, along with various other optional attributes depending on the kind. The order the entries appear in the file from top to bottom determines their order in the project's classpath. Before continuing, it is a good exercise to create a Java project and experiment with that project by changing the Java build path properties, creating entries and modifying the initial default entries to arrive at the .classpath file shown in Listing 1.
Listing 1. Sample .classpath file showing all entry kinds
<?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path="src"/> <classpathentry kind="lib" path="lib/derby.jar" sourcepath="lib/derby-src.jar"/> <classpathentry kind="var" path="ECLIPSE_HOME/startup.jar"/> <classpathentry combineaccessrules="false" kind="src" path="/bar"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="output" path="bin"/> </classpath> |
Listing 1 shows six classpath entries marked by five kind
s. In the underlying Eclipse Java model, each of these is represented by an org.eclipse.jdt.core.IClasspathEntry
type, which categorizes the entry-by-entry kind
and content kind
. A content kind
is defined for most entry kind
s and is either source (org.eclipse.jdt.core.IPackageFragmentRoot.K_SOURCE
) or binary (IPackageFragmentRoot.K_BINARY
). In Eclipse V3.2, the IClasspathEntry
interface defines five constants to refer to the classpath entry kind
, but these are not the same five marked in Listing 1. In fact, one shown in this file — namely output
— is not defined as a constant in IClasspathEntry
, and another — src
— is shown twice in Listing 1 because the two are represented as separate constants in IClasspathEntry
. This makes it a little confusing, but let's ignore that for now and start from the top of the file.
The first entry in Listing 1 has kind="src"
with path="src"
. This indicates that the project has a source folder located in a directory relative to the project root called src
. This will have several implications for the project — most notably, it tells the Java builder that it needs to compile the source located in the src directory. This entry kind is represented by the constantIClasspathEntry.CPE_SOURCE
and has a content kind
of IPackageFragmentRoot.K_BINARY
. When Java projects are created, they inherit default source and output folders from workspace preferences (in Eclipse see Window > Preferences > Java > Build Path). In a fresh Eclipse installation, the source and output folders will be set to the root project folder. The first src
entry in Listing 1 has a path="src"
because the workspace default source folder was changed to src.
The second entry in Listing 1 has kind="lib"
with path="lib/derby.jar"
. This indicates that there is a binary classpath entry located at lib/derby.jar relative to the project root. lib
entries refer to a set of class files with the path attribute specifying a directory of .class files or an archive file that includes .class files. This entry also includes the optional sourcepath
attribute, which refers to the location of the source attachment. The lib kind
entry is represented by the entry kind
constantIClasspathEntry.CPE_LIBRARY
and has a content kind
of IPackageFragmentRoot.K_BINARY
.
The third entry in Listing 1 has kind="var"
with path="ECLIPSE_HOME/startup.jar"
. In this entry, ECLIPSE_HOME
is a variable. This built-in variable provided by Eclipse refers to the Eclipse installation directory. Custom variables can also be defined by the user for a workspace. Paths to classpath files are always relative to the project directory or absolute. So it's good practice to use variables for referencing files outside the project directory to avoid absolute paths, which will make the project difficult to share across different environments. See Window > Preferences > Java > Build Path > Classpath Variables for a list of the variables defined in your workspace. After a variable is defined, it can be used in the build path settings by extending it to refer to a file that is located relative to the variable.
In this case, it was extended by adding the Eclipse startup.jar. var
entries are similar to lib
entries, except that the first element in the path is evaluated before using it in the classpath. Another difference between var
and lib
entries is that lib
entries can reference an archive or a folder of classes, whereas var
entries can only reference an archive. The var kind
is a binary type of entry represented by the constant IClasspathEntry.CPE_VARIABLE
and the content kind
is undefined. So, you should never usegetContentKind()
when referring to an IClasspathEntry with kind="var"
. It is interesting to note, however, that one can only add binary variable extensions to the classpath, and to make it confusing, getContentKind()
always returnsIPackageFragmentRoot.K_SOURCE
for variable entries.
The fourth entry in Listing 1 has kind="src"
with path="/bar"
. This entry references the source of another project in the workspace (notice that the path starts with /
, which refers to the workspace root directory). This will, in effect, add the configured output folder for the /bar project to the compilation classpath, as well as any classpath entries exported from the project. While the kind
attribute is equal to "src"
, as it is with IClasspathEntry.CPE_SOURCE
above, this entry is represented by a different entrykind
constant, IClasspathEntry.CPE_PROJECT
, and it has a content kind
of IPackageFragmentRoot.K_SOURCE
. The only difference in the .classpath entry is that the path attribute is relative to the workspace, instead of the project.
The fifth entry in Listing 1 has kind="con"
with path="org.eclipse.jdt.launching.JRE_CONTAINER"
. This type of entry is the subject of this tutorial. The kind
constant for this entry is IClasspathEntry.CPE_CONTAINER
, and the content kind
is undefined. A container entry is a logical reference to an implementation of org.eclipse.jdt.core.IClasspathContainer
. The implementation aggregates a set of concrete entries, either of type IClasspathEntry.CPE_LIBRARY
or IClasspathEntry.CPE_PROJECT
.
A summary of the classpath entry types is provided below. The example entries are taken from the .classpath file shown inListing 1.
Table 1. Summary classification of classpath entries in Listing 1
CPE_SOURCE | K_SOURCE | |
CPE_LIBRARY | K_BINARY | |
CPE_VARIABLE | undefined | |
CPE_PROJECT | K_SOURCE | |
CPE_CONTAINER | undefined |
For a detailed explanation of the different classpath entries, read the Javadoc for org.eclipse.jdt.core.IClasspathEntry
, and for a good lesson on setting the build path programmatically with these different kind
s, read the Eclipse help topic "Setting the Java Build Path."
What are classpath containers?
In this tutorial, the term classpath container refers to an implementation of org.eclipse.jdt.core.IClasspathContainer
. Classpath containers are logical references to a set of classpath resources. Their entry sets can be defined per project by theIClasspathContainer
implementation. Since the entry set is defined by the IClasspathContainer
, it can be dynamic or static. As an example of the static case, a container could return a fixed set of JARs that are located in a well-known directory (e.g., the JRE System Library). Or, in a more dynamic case, a container might return a set of runtime JARs that changes depending on server deployment.
There are many reasons why one might want to use a classpath container. Here are the more important ones:
And the number of entries needed in the .classpath file is reduced from several to one.
发表评论
-
groovy shell 安全
2017-01-18 11:29 1169groovy 可以动态执行代码,但是我们也想他在一定的沙箱中 ... -
eclipse 插件
2016-11-17 12:00 553eclipse remote editor https: ... -
java method signature
2013-08-12 21:07 2676case 'B': _type = T_BYT ... -
eclipse显示GC的按钮
2013-06-18 19:32 4281同事说idea的一个比较亮的功能是可以手动去GC,然后机器 ... -
好用的maven插件收集
2013-02-22 10:40 13091:Maven Shade Plugin(把所有jar打到一 ... -
查看JVM Flags
2013-01-09 14:22 1300-XX:+PrintFlagsFinal Jav ... -
开源的好用JVM问题排查工具
2013-01-08 09:45 1825TProfiler https://github.com/ ... -
java ocr
2013-01-04 13:06 2947java OCR相关的资料记录 Clara OC ... -
eclipse ast
2012-12-23 22:36 974Eclipse JDT - Abstract Syntax ... -
正则生成器
2012-12-23 22:24 933能够依据普通文本给出可能的正则组合 http://ww ... -
Kilim
2012-12-14 23:40 1071Java 开发 2.0: Kilim 简介 h ... -
IO Design Patterns Reactor VS Proactor
2012-11-13 01:34 14681:两种高性能I/O设计模式(Reactor/Proactor ... -
antlr
2012-11-13 00:36 11891:使用 Antlr 开发领域语言 http://www.i ... -
java singalException
2012-11-12 21:39 948之前看到毕大师一封关于异常多造成的cpu us很高的分析邮件, ... -
log4j Category.callAppenders Block
2012-11-06 17:01 10022经常在高并发下就遇到log4j用错引起的线程block住的问题 ... -
Troubleshooting JDK
2012-10-26 14:13 1488收集整理下JDK自带的关于 Troubleshooting 的 ... -
JavaOne 2011 Content Catalog
2012-10-14 17:12 1137上一篇讲javaone 2012,这次找了下2011的资料。 ... -
JavaOne 2012 Content Catalog
2012-10-13 16:07 1273转载自:http://marxsoftware.blogspo ... -
Memory usage of Java
2012-10-01 17:30 1192用JDK自带的api计算size,每次都会有个多余的12,看了 ... -
GC roots
2012-10-01 17:07 18201:GC roots http://www.yourkit. ...
相关推荐
NULL 博文链接:https://wangbing9577.iteye.com/blog/2175197
本文详细叙述了.classpath中各种属性的含义
Classpath Variable 解决办法
.classpath
主要介绍了Spring配置中的"classpath:"与"classpath*:"的区别,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
classpath修改,相关jsp页面classpath修改
关于java的classpath补充,详细说明如何配置classpath,如火热让javac正确编译运行java文件
3. 配置Java环境变量: JAVA_HOME,PATH,CLASSPATH 4. 安装Eclipse TestNG插件 4.1 打开Eclipse,Help菜单里的 InstallNew Software 4.2 选择Add,在location里输入http://beust.com/eclipse 4.3 选择TestNG,点...
在用eclipse 搭建hadoop插件时,apache不会提供插件,插件必须自己编译并且声称jar包。 1、将hadoop-1.1.2.tar.gz解压。比如:D:\hadoop-1.1.2。 2、进入D:\hadoop-1.1.2\src\contrib目录。将build-contrib.xml...
classpath备份
Android 4.4.4源码的.classpath文件,主要用于将Android 4.4.4源码的导入到eclipse工具中,提供给需要学习android源码的同学,也自己顺便记录一下,方便查找。
hadoop 1.1.2 的eclipse 插件 经测试可用 如不可用 可以参考如下自行编译 首先将 ${HADOOP_HOME}\src\contrib 下面的 build-contrib.xml 复制到 ${HADOOP_HOME}\src\contrib\eclipse-plugin 下面 然后修改 build-...
eclipse的离线resin插件 ResinLauncher: launch resin 2.x or 3.x (require JDK 1.4) within eclipse to let you debug jsp or servlet. If you are using jdk ...ResinWarFile: create war file for you using ant.
java classpath 理解 包括 1 在命令行查看classpath 2 在命令行设置classpath 3 classpath理解 4 命令行中直接使用classpath 很经典哦
jdk的classpath路径和环境配置 jdk的classpath路径和环境配置
classpath 和path
每一个项目目录中的.classpath文件是Eclipse的项目路径文件;.project文件是Eclipse项目的项目描述文件。读者可以通过两种方法使用这些源代码: (1)从头创建项目,这种方式要求读者根据书中介绍的方法创建项目、包...
一、ClassPath Helper 说明: 1.depends on:表示该类依赖于下面的jar包列表。 2.refrenced by:表示该类被下面的jar列表所依赖。 3.unresolved references:表示该类下的某些方法,找不到依赖jar包。一般出错时就是...