classpath

package
v0.0.0-...-09ea784 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 18, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Classpath

type Classpath struct {
	// contains filtered or unexported fields
}

Classpath : 启动类路径默认对应jre\lib目录,Java标准库(大部分在rt.jar里)位于该路径。 扩展类路径默认对应jre\lib\ext目录,使用Java扩展机制的类位于这个路径。 我们自己实现的类,以及第三方类库则位于用户类路径。可以通过-Xbootclasspath选项修改启动类路径,不过通常并不需要这样做。

用户类路径的默认值是当前目录,也就是“.”。可以设置CLASSPATH环境变量来修改用户类路径, 但是这样做不够灵活,所以不推荐使用。更好的办法是给java命令传递-classpath(或简写为-cp)选项。 -classpath/-cp选项的优先级更高,可以覆盖CLASSPATH环境变量设置。 -classpath/-cp选项既可以指定目录,也可以指定JAR文件或者ZIP文件,还可以同时指定多个目录或文件,用分隔符分开即可。

分隔符因操作系统而异。在Windows系统下是分号,在类UNIX(包括Linux、Mac OS X等)系统下是冒号。例如在Windows下: java -cp path\to\classes;lib\a.jar;lib\b.jar;lib\c.zip ...

func Parse

func Parse(jreOption, cpOption string) *Classpath

Parse : 使用 -Xjre 选项解析启动类路径和扩展类路径,使用 -classpath/-cp 选项解析用户类路径

func (*Classpath) ReadClass

func (c *Classpath) ReadClass(className string) ([]byte, Entry, error)

ReadClass : 如果用户没有提供 -classpath/-cp 选项,则使用当前目录作为用户类路径。 ReadClass()方法依次从启动类路径、扩展类路径和用户类路径中搜索class文件。 注意:传递给 ReadClass()方法的类名不包含“.class”后缀。

func (*Classpath) String

func (c *Classpath) String() string

返回用户类路径的字符串表示

type CompositeEntry

type CompositeEntry []Entry

CompositeEntry 由更小的 Entry组成,正好可以表示成 []Entry

func (CompositeEntry) String

func (c CompositeEntry) String() string

调用每一个子路径的 String()方法,然后把得到的字符串用路径分隔符拼接起来

type DirEntry

type DirEntry struct {
	// contains filtered or unexported fields
}

目录形式的类路径

func (*DirEntry) String

func (d *DirEntry) String() string

type Entry

type Entry interface {

	// 返回字符串表示
	String() string
	// contains filtered or unexported methods
}

定义一个接口来表示类路径项

type ZipEntry

type ZipEntry struct {
	// contains filtered or unexported fields
}

ZIP或JAR文件形式的类路径

func (*ZipEntry) String

func (z *ZipEntry) String() string

type ZipEntry2

type ZipEntry2 struct {
	// contains filtered or unexported fields
}

func (*ZipEntry2) String

func (z *ZipEntry2) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL