public final class ClassPath extends Object
A client may obtain a ClassPath instance using
ClassPath.getClassPath(id)
static method, where the ID is an
abstract name for the classpath wanted. There are some predefined classpath
names predefined as symbolic constants, following individual types of services
(compiler, debugger, executor). Names are not limited to the listed ones; an extension
module might add its own private classpath type.
Modifier and Type | Class and Description |
---|---|
class |
ClassPath.Entry
Represents an individual entry in the ClassPath.
|
static class |
ClassPath.Flag
ClassPath's flags.
|
static class |
ClassPath.PathConversionMode
Policy for handling path items which cannot be converted into the desired format.
|
static class |
ClassPath.PathEmbeddingMode
Policy for handling in archive path.
|
Modifier and Type | Field and Description |
---|---|
static String |
BOOT
Boot ClassPath of the JDK.
|
static String |
COMPILE
ClassPath for compiling things.
|
static String |
DEBUG
Deprecated.
Probably useless.
|
static ClassPath |
EMPTY
The empty ClassPath.
|
static String |
EXECUTE
Classpath setting for executing things.
|
static String |
PROP_ENTRIES
Name of the "entries" property
|
static String |
PROP_FLAGS
Name of the "flags" property
|
static String |
PROP_INCLUDES
Property to be fired when include/exclude set changes.
|
static String |
PROP_ROOTS
Name of the "roots" property
|
static String |
SOURCE
ClassPath for project sources.
|
Modifier and Type | Method and Description |
---|---|
void |
addPropertyChangeListener(PropertyChangeListener l)
Adds a property change listener to the bean.
|
boolean |
contains(FileObject f)
Checks whether a FileObject lies on this classpath.
|
List<ClassPath.Entry> |
entries()
Returns list of classpath entries from the ClassPath definition.
|
boolean |
equals(Object obj) |
List<FileObject> |
findAllResources(String resourceName)
Gives out an ordered collection containing all FileObjects, which correspond
to a given ResourceName; only the first one is seen by the ClassLoader
at runtime or can be linked against.
|
FileObject |
findOwnerRoot(FileObject resource)
Finds a root in this ClassPath, that owns the given file.
|
FileObject |
findResource(String resourceName)
Returns a FileObject for the specified resource.
|
ClassLoader |
getClassLoader(boolean cache)
Returns a ClassLoader for loading classes from this ClassPath.
|
static ClassPath |
getClassPath(FileObject f,
String id)
Find the classpath of a given type, if any, defined for a given file.
|
Set<ClassPath.Flag> |
getFlags()
Returns the
ClassPath 's flags. |
String |
getResourceName(FileObject f)
Creates a suitable resource name for the given FileObject within the
classpath.
|
String |
getResourceName(FileObject f,
char dirSep,
boolean includeExt)
Computes a resource name for the FileObject, which uses `pathSep' character
as a directory separator.
|
FileObject[] |
getRoots()
Retrieves valid roots of ClassPath, in the proper order.
|
int |
hashCode() |
boolean |
isResourceVisible(FileObject resource)
Determines if the resource is visible in the classpath,
that is if the file will be reached when a process attempts to
load a resource of that name.
|
void |
removePropertyChangeListener(PropertyChangeListener l)
Removes the listener registered by
addPropertyChangeListener . |
String |
toString()
|
String |
toString(ClassPath.PathConversionMode conversionMode)
Render this classpath in the conventional format used by the Java launcher.
|
String |
toString(ClassPath.PathConversionMode conversionMode,
ClassPath.PathEmbeddingMode pathEmbeddingMode)
Render this classpath in the conventional format used by the Java launcher.
|
public static final String EXECUTE
It corresponds to the -classpath
option to java
(the Java launcher): i.e. all compiled classes outside the JRE that
will be needed to run the program, or at least to load a certain class.
It may also be thought of as corresponding to the list of URLs in a
URLClassLoader
(plus URLs present in parent class loaders
but excluding the bootstrap and extension class loaders).
@Deprecated public static final String DEBUG
public static final String COMPILE
It corresponds to the -classpath
option to javac
:
i.e. already-compiled classes which some new sources need to compile against,
besides what is already in the JRE.
public static final String SOURCE
It is similar to the -sourcepath
option of javac
.
For typical source files, the sourcepath will consist of one element: the package root of the source file. If more than one package root is to be compiled together, all the sources should share a sourcepath with multiple roots.
Note that each source file for which editor code completion (and similar actions) should work should have a classpath of this type.
public static final String BOOT
It corresponds to the -Xbootclasspath
and -Xext
options to java
(the Java launcher): i.e. all compiled
classes in the JRE that will be needed to run the program.
It may also be thought of as corresponding to the classes loadable
by the primordial bootstrap class loader plus the standard
extension and endorsed-library class loaders; i.e. class loaders lying
below the regular application startup loader and any custom loaders.
Generally there ought to be a single boot classpath for the entire
application.
public static final String PROP_ROOTS
public static final String PROP_ENTRIES
public static final String PROP_FLAGS
public static final String PROP_INCLUDES
FilteringPathResourceImplementation
,
Constant Field Valuespublic static final ClassPath EMPTY
public FileObject[] getRoots()
includes and excludes
.public List<ClassPath.Entry> entries()
public final FileObject findResource(String resourceName)
FileObject
for the first package fragment
in the ClassPath
.
FilteringPathResourceImplementation
may cause an actual file
beneath a registered root to not be returned.
Note: do not pass names starting with slash to this method.resourceName
- name of the resource as it would be passed
to ClassLoader.getResource(java.lang.String)
public final List<FileObject> findAllResources(String resourceName)
FilteringPathResourceImplementation
may cause an actual file
beneath a registered root to not be returned.resourceName
- resource namepublic final String getResourceName(FileObject f)
null
if the fileobject
is not underneath any of classpath roots.excluded
), the resource name is still returned.f
- FileObject whose resource name is requestedpublic final String getResourceName(FileObject f, char dirSep, boolean includeExt)
f
- FileObject whose resource name is requested.dirSep
- directory separator characterincludeExt
- whether the FileObject's extension should be included in the result@CheckForNull public final FileObject findOwnerRoot(FileObject resource)
FilteringPathResourceImplementation
excluded) are still considered
to be part of the classpath and "owned" by one of its roots.
resource
- resource to find root for.public final boolean contains(FileObject f)
FilteringPathResourceImplementation
is considered.f
- the FileObject to checkpublic final boolean isResourceVisible(FileObject resource)
excluded
.resource
- the resource whose visibility should be testedpublic final void addPropertyChangeListener(PropertyChangeListener l)
l
- a listener to addpublic final void removePropertyChangeListener(PropertyChangeListener l)
addPropertyChangeListener
.l
- a listener to remove@NonNull public Set<ClassPath.Flag> getFlags()
ClassPath
's flags.ClassPath.Flag
s@CheckForNull public static ClassPath getClassPath(@NonNull FileObject f, @NonNull String id)
This method may return null, if:
id
parameter) is not recognized
Generally you may pass either an individual Java file, or the root of a Java package tree, interchangeably, since in most cases all files in a given tree will share a single classpath.
Typically classpaths for files are defined by the owning project, but
there may be other ways classpaths are defined. See ClassPathProvider
for more details.
f
- the file, whose classpath settings should be returned (may not be null as of org.netbeans.api.java/1 1.4)id
- the type of the classpath (e.g. ClassPath.COMPILE
)null
, if
there is no classpath availableClassPathProvider
@NonNull public String toString(@NonNull ClassPath.PathConversionMode conversionMode, @NonNull ClassPath.PathEmbeddingMode pathEmbeddingMode)
conversionMode
- policy for converting unusual entriespathEmbeddingMode
- policy for handling in archive pathFile.pathSeparator
,
FileUtil.archiveOrDirForURL(java.net.URL)
,
ClassPathSupport.createClassPath(String)
@NonNull public String toString(@NonNull ClassPath.PathConversionMode conversionMode)
conversionMode
- policy for converting unusual entriesFile.pathSeparator
,
FileUtil.archiveOrDirForURL(java.net.URL)
,
ClassPathSupport.createClassPath(String)
public final ClassLoader getClassLoader(boolean cache)
If cache
is false, then
the method will always return a new class loader. If that parameter is true,
the method may return a loader which survived from a previous call to the same ClassPath
.
cache
- true if it is permissible to cache class loaders between calls