- 浏览: 2107047 次
- 性别:
- 来自: 杭州
文章分类
最新评论
-
无心流泪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 1202groovy 可以动态执行代码,但是我们也想他在一定的沙箱中 ... -
eclipse 插件
2016-11-17 12:00 612eclipse remote editor https: ... -
java method signature
2013-08-12 21:07 2720case 'B': _type = T_BYT ... -
eclipse显示GC的按钮
2013-06-18 19:32 4339同事说idea的一个比较亮的功能是可以手动去GC,然后机器 ... -
好用的maven插件收集
2013-02-22 10:40 13501:Maven Shade Plugin(把所有jar打到一 ... -
查看JVM Flags
2013-01-09 14:22 1335-XX:+PrintFlagsFinal Jav ... -
开源的好用JVM问题排查工具
2013-01-08 09:45 1862TProfiler https://github.com/ ... -
java ocr
2013-01-04 13:06 3024java OCR相关的资料记录 Clara OC ... -
eclipse ast
2012-12-23 22:36 1014Eclipse JDT - Abstract Syntax ... -
正则生成器
2012-12-23 22:24 977能够依据普通文本给出可能的正则组合 http://ww ... -
Kilim
2012-12-14 23:40 1110Java 开发 2.0: Kilim 简介 h ... -
IO Design Patterns Reactor VS Proactor
2012-11-13 01:34 15101:两种高性能I/O设计模式(Reactor/Proactor ... -
antlr
2012-11-13 00:36 12201:使用 Antlr 开发领域语言 http://www.i ... -
java singalException
2012-11-12 21:39 982之前看到毕大师一封关于异常多造成的cpu us很高的分析邮件, ... -
log4j Category.callAppenders Block
2012-11-06 17:01 10115经常在高并发下就遇到log4j用错引起的线程block住的问题 ... -
Troubleshooting JDK
2012-10-26 14:13 1526收集整理下JDK自带的关于 Troubleshooting 的 ... -
JavaOne 2011 Content Catalog
2012-10-14 17:12 1170上一篇讲javaone 2012,这次找了下2011的资料。 ... -
JavaOne 2012 Content Catalog
2012-10-13 16:07 1309转载自:http://marxsoftware.blogspo ... -
Memory usage of Java
2012-10-01 17:30 1218用JDK自带的api计算size,每次都会有个多余的12,看了 ... -
GC roots
2012-10-01 17:07 18501:GC roots http://www.yourkit. ...
相关推荐
标题 "JUnit Ant Eclipse, JUnitReport报告" 涉及到的是在软件开发过程中,使用JUnit进行单元测试,结合Ant构建工具生成测试报告,并在Eclipse集成开发环境中进行管理和查看的过程。这里我们将详细探讨这三个核心...
- 将 Hadoop 的 JAR 包添加到 Eclipse 的 Classpath 中。 - 在 Eclipse 的项目上右键,选择 “Properties” > “Java Build Path” > “Libraries”。 - 点击 “Add External JARs...”,选择 Hadoop 目录下的...
[2015-06-12 12:26:57 - Iphone] Conversion to Dalvik format failed: Unable to execute dex: method ID not in [0, 0xffff]: 65536 ``` 这表明应用中的方法数已经超过了 Dalvik 虚拟机能处理的最大值。 #### 三...
sourceanalyzer -b <build-id> -cp <classpath> <file-list> ●附注参数:-Xmx;- encoding-jdk;- appserver- appserver- veron -appserver-home Table 1: File specifiers File specifier Description darna盈e All ...
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib export PATH=${JAVA_HOME}/bin:$PATH ``` - 保存并关闭文件后,执行`source ~/.bashrc`使更改生效。 #### 安装Eclipse 1. **下载Eclipse:** - 访问...
System.err.format("Error reading file: %s%n", e.getMessage()); } System.out.println("File contains " + lineCount + " lines."); } } ``` 上述代码创建了一个`BufferedReader`实例,然后使用`readLine()`...
为了在Eclipse中运行这个示例,确保项目结构包含`.classpath`和`.project`文件,这表明这是一个Eclipse项目。`lib`目录可能包含了Apache POI的JAR文件,而`.settings`目录包含项目的配置信息。`bin`目录通常是编译后...
在本项目中,"tif_demo.zip" 是一个包含Spring Boot应用程序的压缩文件,该程序旨在演示如何在前端使用tiff.js库来展示由后端返回的TIFF(Tagged Image File Format)图像文件。TIFF是一种广泛用于存储高质量图像的...
为了在Eclipse中正确配置Hibernate,首先需要设置Classpath Variables来指向Hibernate安装路径下的核心库文件。具体步骤如下: 1. 打开Eclipse并选择`Window -> Preferences`打开首选项对话框。 2. 在左侧菜单中...
`.classpath`和`.project`文件是Eclipse项目配置,`.settings`是Eclipse工作空间设置,`lib`目录可能包含项目依赖的JAR文件,而`bin`目录通常包含编译后的类文件。 整合Lucene与JavaWeb需要理解Lucene的核心概念和...
通常,在IDE(如Eclipse或IntelliJ IDEA)中,可通过项目构建路径或Maven依赖管理来完成这一操作。 #### 创建Excel文件 创建一个Excel文件涉及使用`WritableWorkbook`对象,它是负责创建新工作簿的核心类。下面的...
- **.classpath**:记录了项目所需的类库路径,包括ZXing库的引用。 - **lib**:可能包含了ZXing库的JAR文件,作为项目的依赖。 5. **注意事项** - 二维码的内容有限制,过长的数据可能会导致生成失败或读取困难...
FormatOutput=true/false 当输出内容时是否自动格式化代码 FormatSource=true/false 在切换到代码视图时是否自动格式化代码 FullPage=true/false 是否允许编辑整个HTML文件,还是仅允许编辑BODY间的内容 ...
在开发环境中,通常通过IDE(如Eclipse、IntelliJ IDEA)自动管理类路径。在生产环境中,需要确保所有的依赖库被正确地添加到服务器的类路径中。在Tomcat中,可以在`$CATALINA_HOME/lib`目录下放置JAR文件,或者在`...
<taskdef name="hibernatedoclet" classname="xdoclet.modules.hibernate.HibernateDocletTask" classpathref="app.classpath"/> <!-- 执行生成映射文件 --> ,@author,@todo"> <fileset dir="src/java"> **/po...
<format pattern="yyyyMMddhhmm" property="pktime" unit="hour"/> <!-- 创建apk存放目录 --> ${apk.dir}"/> <!-- 将第三方jar包添加到classpath变量中 --> ${toString:project.all.jars.path}"/> ${tz....
`.classpath`和`.project`文件是Eclipse的工作空间配置文件,它们包含了项目的类路径和项目设置信息,主要用于IDE的项目管理。`.settings`目录包含了Maven项目的用户特定配置,这些文件通常是IDE自动生成的,对于...