Eclipse JDT
2.0

org.eclipse.jdt.launching
Class JavaRuntime

java.lang.Object
  |
  +--org.eclipse.jdt.launching.JavaRuntime

public final class JavaRuntime
extends Object

The central access point for launching support. This class manages the registered VM types contributed through the "org.eclipse.jdt.launching.vmType" extension point. As well, this class provides VM install change notification, and computes classpaths and source lookup paths for launch configurations.

This class provides static methods only; it is not intended to be instantiated or subclassed by clients.


Field Summary
static String ATTR_CMDLINE
          Attribute key for a process property.
static int DEF_CONNECT_TIMEOUT
          Default launch/connect timeout (ms).
static int ERR_UNABLE_TO_RESOLVE_JRE
          A status code indicating that a JRE could not be resolved for a project.
static String EXTENSION_POINT_RUNTIME_CLASSPATH_ENTRY_RESOLVERS
          Simple identifier constant (value "runtimeClasspathEntryResolvers") for the runtime classpath entry resolvers extension point.
static String EXTENSION_POINT_RUNTIME_CLASSPATH_PROVIDERS
          Simple identifier constant (value "classpathProviders") for the runtime classpath providers extension point.
static String JRE_CONTAINER
          Classpath container used for a project's JRE.
static String JRELIB_VARIABLE
          Classpath variable name used for the default JRE's library.
static String JRESRC_VARIABLE
          Classpath variable name used for the default JRE's library source.
static String JRESRCROOT_VARIABLE
          Classpath variable name used for the default JRE's library source root.
static String PREF_CONNECT_TIMEOUT
          Preference key for launch/connect timeout.
 
Method Summary
static void addContainerResolver(IRuntimeClasspathEntryResolver resolver, String containerIdentifier)
          Registers the given resolver for the specified container.
static void addVariableResolver(IRuntimeClasspathEntryResolver resolver, String variableName)
          Registers the given resolver for the specified variable.
static void addVMInstallChangedListener(IVMInstallChangedListener listener)
          Adds the given listener to the list of registered VM install changed listeners.
static String[] computeDefaultRuntimeClassPath(IJavaProject jproject)
          Computes the default application classpath entries for the given project.
static IRuntimeClasspathEntry[] computeUnresolvedRuntimeClasspath(IJavaProject project)
          Computes and returns the default unresolved runtime claspath for the given project.
static IRuntimeClasspathEntry[] computeUnresolvedRuntimeClasspath(ILaunchConfiguration configuration)
          Computes and returns the unresolved class path for the given launch configuration.
static IRuntimeClasspathEntry[] computeUnresolvedSourceLookupPath(ILaunchConfiguration configuration)
          Computes and returns the unresolved source lookup path for the given launch configuration.
static IVMInstall computeVMInstall(ILaunchConfiguration configuration)
          Returns the VM install for the given launch configuration.
static void fireVMAdded(IVMInstall vm)
          Notifies all VM install changed listeners of the VM addition
static void fireVMChanged(PropertyChangeEvent event)
          Notifies all VM install changed listeners of the given property change.
static void fireVMRemoved(IVMInstall vm)
          Notifies all VM install changed listeners of the VM removal
static IRuntimeClasspathProvider getClasspathProvider(ILaunchConfiguration configuration)
          Returns the classpath provider for the given launch configuration.
static IClasspathEntry getDefaultJREContainerEntry()
          Creates and returns a classpath entry describing the default JRE container entry.
static IVMConnector getDefaultVMConnector()
          Return the default VM connector.
static IVMInstall getDefaultVMInstall()
          Return the default VM set with setDefaultVM().
static IJavaProject getJavaProject(ILaunchConfiguration configuration)
          Return the IJavaProject referenced in the specified configuration or null if none.
static IClasspathEntry getJREVariableEntry()
          Creates and returns a classpath entry describing the JRE_LIB classpath variable.
static LibraryLocation[] getLibraryLocations(IVMInstall vm)
          Evaluates library locations for a IVMInstall.
static Preferences getPreferences()
          Returns the preference store for the launching plug-in.
static IRuntimeClasspathProvider getSourceLookupPathProvider(ILaunchConfiguration configuration)
          Returns the source lookup path provider for the given launch configuration.
static IVMConnector getVMConnector(String id)
          Returns the VM connetor defined with the specified identifier, or null if none.
static IVMConnector[] getVMConnectors()
          Returns all VM connector extensions.
static IVMInstall getVMInstall(IJavaProject project)
          Returns the VM assigned to build the given Java project.
static IVMInstallType getVMInstallType(String id)
          Returns the VM install type with the given unique id.
static IVMInstallType[] getVMInstallTypes()
          Returns the list of registered VM types.
static IRuntimeClasspathEntry newArchiveRuntimeClasspathEntry(IPath path)
          Returns a new runtime classpath entry for the given archive (possibly external).
static IRuntimeClasspathEntry newArchiveRuntimeClasspathEntry(IResource resource)
          Returns a new runtime classpath entry for the given archive.
static IRuntimeClasspathEntry newProjectRuntimeClasspathEntry(IJavaProject project)
          Returns a new runtime classpath entry for the given project.
static IRuntimeClasspathEntry newRuntimeClasspathEntry(String memento)
          Returns a runtime classpath entry constructed from the given memento.
static IRuntimeClasspathEntry newRuntimeContainerClasspathEntry(IPath path, int classpathProperty)
          Returns a runtime classpath entry for the given container path with the given classpath property.
static IRuntimeClasspathEntry newVariableRuntimeClasspathEntry(IPath path)
          Returns a new runtime classpath entry for the classpath variable with the given path.
static void removeVMInstallChangedListener(IVMInstallChangedListener listener)
          Removes the given listener from the list of registered VM install changed listeners.
static IRuntimeClasspathEntry[] resolveRuntimeClasspath(IRuntimeClasspathEntry[] entries, ILaunchConfiguration configuration)
          Resolves the given classpath, returning the resolved classpath in the context of the given launch configuration.
static IRuntimeClasspathEntry[] resolveRuntimeClasspathEntry(IRuntimeClasspathEntry entry, IJavaProject project)
          Returns resolved entries for the given entry in the context of the given Java project.
static IRuntimeClasspathEntry[] resolveRuntimeClasspathEntry(IRuntimeClasspathEntry entry, ILaunchConfiguration configuration)
          Returns resolved entries for the given entry in the context of the given launch configuration.
static IRuntimeClasspathEntry[] resolveSourceLookupPath(IRuntimeClasspathEntry[] entries, ILaunchConfiguration configuration)
          Resolves the given source lookup path, returning the resolved source lookup path in the context of the given launch configuration.
static void savePreferences()
          Saves the preferences for the launching plug-in.
static void saveVMConfiguration()
          Saves the VM configuration information to disk.
static void setDefaultVMConnector(IVMConnector connector, IProgressMonitor monitor)
          Sets a VM connector as the system-wide default VM.
static void setDefaultVMInstall(IVMInstall vm, IProgressMonitor monitor)
          Sets a VM as the system-wide default VM, and notifies registered VM install change listeners of the change.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JRELIB_VARIABLE

public static final String JRELIB_VARIABLE
Classpath variable name used for the default JRE's library.

See Also:
Constant Field Values

JRESRC_VARIABLE

public static final String JRESRC_VARIABLE
Classpath variable name used for the default JRE's library source.

See Also:
Constant Field Values

JRESRCROOT_VARIABLE

public static final String JRESRCROOT_VARIABLE
Classpath variable name used for the default JRE's library source root.

See Also:
Constant Field Values

EXTENSION_POINT_RUNTIME_CLASSPATH_ENTRY_RESOLVERS

public static final String EXTENSION_POINT_RUNTIME_CLASSPATH_ENTRY_RESOLVERS
Simple identifier constant (value "runtimeClasspathEntryResolvers") for the runtime classpath entry resolvers extension point.

Since:
2.0
See Also:
Constant Field Values

EXTENSION_POINT_RUNTIME_CLASSPATH_PROVIDERS

public static final String EXTENSION_POINT_RUNTIME_CLASSPATH_PROVIDERS
Simple identifier constant (value "classpathProviders") for the runtime classpath providers extension point.

Since:
2.0
See Also:
Constant Field Values

JRE_CONTAINER

public static final String JRE_CONTAINER
Classpath container used for a project's JRE. A container is resolved in the context of a specific Java project, to one or more system libraries contained in a JRE. The container can have zero or two path segments following the container name. When no segments follow the container name, the workspace default JRE is used to build a project. Otherwise the segments identify a specific JRE used to build a project:
  1. VM Install Type Identifier - identifies the type of JRE used to build the project. For example, the standard VM.
  2. VM Install Name - a user defined name that identifies that a specific VM of the above kind. For example, IBM 1.3.1. This information is shared in a projects classpath file, so teams must agree on JRE naming conventions.

Since:
2.0

ERR_UNABLE_TO_RESOLVE_JRE

public static final int ERR_UNABLE_TO_RESOLVE_JRE
A status code indicating that a JRE could not be resolved for a project. When a JRE cannot be resolved for a project by this plug-in's container initializer, an exception is thrown with this status code. A status handler may be registered for this status code. The source object provided to the status handler is the Java project for which the path could not be resolved. The status handler must return an IVMInstall or null. The container resolver will re-set the project's classpath if required.

Since:
2.0
See Also:
Constant Field Values

PREF_CONNECT_TIMEOUT

public static final String PREF_CONNECT_TIMEOUT
Preference key for launch/connect timeout. VM Runners should honor this timeout value when attempting to launch and connect to a debuggable VM. The value is an int, indicating a number of millieseconds.

Since:
2.0

DEF_CONNECT_TIMEOUT

public static final int DEF_CONNECT_TIMEOUT
Default launch/connect timeout (ms).

Since:
2.0
See Also:
Constant Field Values

ATTR_CMDLINE

public static final String ATTR_CMDLINE
Attribute key for a process property. The class org.eclipse.debug.core.model.IProcess allows attaching String properties to processes. The value of this attribute is the command line a process was launched with. Implementers of IVMRunner should use this attribute key to attach the command lines to the processes they create.

Method Detail

getVMInstallTypes

public static IVMInstallType[] getVMInstallTypes()
Returns the list of registered VM types. VM types are registered via "org.eclipse.jdt.launching.vmTypes" extension point. Returns an empty list if there are no registered VM types.

Returns:
the list of registered VM types

getVMInstall

public static IVMInstall getVMInstall(IJavaProject project)
                               throws CoreException
Returns the VM assigned to build the given Java project. The project must exist. The VM assigned to a project is determined from its build path.

Returns:
the VM instance that is assigned to build the given Java project Returns null if no VM is referenced on the project's build path.
Throws:
CoreException - if unable to determine the project's VM install

getVMInstallType

public static IVMInstallType getVMInstallType(String id)
Returns the VM install type with the given unique id.

Returns:
The VM install type for the given id, or null if no VM install type with the given id is registered.

setDefaultVMInstall

public static void setDefaultVMInstall(IVMInstall vm,
                                       IProgressMonitor monitor)
                                throws CoreException
Sets a VM as the system-wide default VM, and notifies registered VM install change listeners of the change.

Parameters:
vm - The vm to make the default. May be null to clear the default.
monitor - progress monitor or null
CoreException

setDefaultVMConnector

public static void setDefaultVMConnector(IVMConnector connector,
                                         IProgressMonitor monitor)
                                  throws CoreException
Sets a VM connector as the system-wide default VM. This setting is persisted when saveVMConfiguration is called.

Parameters:
connector - The connector to make the default. May be null to clear the default.
CoreException
Since:
2.0

getDefaultVMInstall

public static IVMInstall getDefaultVMInstall()
Return the default VM set with setDefaultVM().

Returns:
Returns the default VM. May return null when no default VM was set or when the default VM has been disposed.

getDefaultVMConnector

public static IVMConnector getDefaultVMConnector()
Return the default VM connector.

Returns:
Returns the default VM connector.
Since:
2.0

newProjectRuntimeClasspathEntry

public static IRuntimeClasspathEntry newProjectRuntimeClasspathEntry(IJavaProject project)
Returns a new runtime classpath entry for the given project.

Parameters:
project - Java project
Returns:
runtime classpath entry
Since:
2.0

newArchiveRuntimeClasspathEntry

public static IRuntimeClasspathEntry newArchiveRuntimeClasspathEntry(IResource resource)
Returns a new runtime classpath entry for the given archive.

Parameters:
resource - archive resource
Returns:
runtime classpath entry
Since:
2.0

newArchiveRuntimeClasspathEntry

public static IRuntimeClasspathEntry newArchiveRuntimeClasspathEntry(IPath path)
Returns a new runtime classpath entry for the given archive (possibly external).

Parameters:
path - absolute path to an archive
Returns:
runtime classpath entry
Since:
2.0

newVariableRuntimeClasspathEntry

public static IRuntimeClasspathEntry newVariableRuntimeClasspathEntry(IPath path)
Returns a new runtime classpath entry for the classpath variable with the given path.

Parameters:
path - variable path; first segment is the name of the variable; trailing segments are appended to the resolved variable value
Returns:
runtime classpath entry
Since:
2.0

newRuntimeContainerClasspathEntry

public static IRuntimeClasspathEntry newRuntimeContainerClasspathEntry(IPath path,
                                                                       int classpathProperty)
                                                                throws CoreException
Returns a runtime classpath entry for the given container path with the given classpath property.

Parameters:
path - container path
classpathProperty - the type of entry - one of USER_CLASSES, BOOTSTRAP_CLASSES, or STANDARD_CLASSES
Returns:
runtime classpath entry
Throws:
CoreException - if unable to construct a runtime classpath entry
Since:
2.0

newRuntimeClasspathEntry

public static IRuntimeClasspathEntry newRuntimeClasspathEntry(String memento)
                                                       throws CoreException
Returns a runtime classpath entry constructed from the given memento.

Parameters:
memento - a menento for a runtime classpath entry
Returns:
runtime classpath entry
Throws:
CoreException - if unable to construct a runtime classpath entry
Since:
2.0

computeUnresolvedRuntimeClasspath

public static IRuntimeClasspathEntry[] computeUnresolvedRuntimeClasspath(IJavaProject project)
                                                                  throws CoreException
Computes and returns the default unresolved runtime claspath for the given project.

Returns:
runtime classpath entries
Throws:
CoreException - if unable to compute the runtime classpath
Since:
2.0
See Also:
IRuntimeClasspathEntry

computeUnresolvedSourceLookupPath

public static IRuntimeClasspathEntry[] computeUnresolvedSourceLookupPath(ILaunchConfiguration configuration)
                                                                  throws CoreException
Computes and returns the unresolved source lookup path for the given launch configuration.

Parameters:
configuration - launch configuration
Returns:
runtime classpath entries
Throws:
CoreException - if unable to compute the source lookup path
Since:
2.0

resolveSourceLookupPath

public static IRuntimeClasspathEntry[] resolveSourceLookupPath(IRuntimeClasspathEntry[] entries,
                                                               ILaunchConfiguration configuration)
                                                        throws CoreException
Resolves the given source lookup path, returning the resolved source lookup path in the context of the given launch configuration.

Parameters:
entries - unresolved entries
configuration - launch configuration
Returns:
resolved entries
Throws:
CoreException - if unable to resolve the source lookup path
Since:
2.0

getClasspathProvider

public static IRuntimeClasspathProvider getClasspathProvider(ILaunchConfiguration configuration)
                                                      throws CoreException
Returns the classpath provider for the given launch configuration.

Parameters:
configuration - launch configuration
Returns:
classpath provider
Throws:
CoreException - if unable to resolve the path provider
Since:
2.0

getSourceLookupPathProvider

public static IRuntimeClasspathProvider getSourceLookupPathProvider(ILaunchConfiguration configuration)
                                                             throws CoreException
Returns the source lookup path provider for the given launch configuration.

Parameters:
configuration - launch configuration
Returns:
source lookup path provider
Throws:
CoreException - if unable to resolve the path provider
Since:
2.0

resolveRuntimeClasspathEntry

public static IRuntimeClasspathEntry[] resolveRuntimeClasspathEntry(IRuntimeClasspathEntry entry,
                                                                    ILaunchConfiguration configuration)
                                                             throws CoreException
Returns resolved entries for the given entry in the context of the given launch configuration. If the entry is of kind VARIABLE or CONTAINTER, variable and contanier resolvers are consulted, otherwise, the returned entry is the same as the given entry.

If the given entry is a variable entry, and a resolver is not registered, the entry itself is returned. If the given entry is a container, and a resolver is not registered, resolved runtime classpath entries are calculated from the associated container classpath entries, in the context of the project associated with the given launch configuration.

Parameters:
entry - runtime classpath entry
configuration - launch configuration
Returns:
resolved runtime classpath entry
Throws:
CoreException - if unable to resolve
Since:
2.0
See Also:
IRuntimeClasspathEntryResolver

resolveRuntimeClasspathEntry

public static IRuntimeClasspathEntry[] resolveRuntimeClasspathEntry(IRuntimeClasspathEntry entry,
                                                                    IJavaProject project)
                                                             throws CoreException
Returns resolved entries for the given entry in the context of the given Java project. If the entry is of kind VARIABLE or CONTAINTER, variable and contanier resolvers are consulted, otherwise, the returned entry is the same as the given entry.

If the given entry is a variable entry, and a resolver is not registered, the entry itself is returned. If the given entry is a container, and a resolver is not registered, resolved runtime classpath entries are calculated from the associated container classpath entries, in the context of the given project.

Parameters:
entry - runtime classpath entry
project - Java project context
Returns:
resolved runtime classpath entry
Throws:
CoreException - if unable to resolve
Since:
2.0
See Also:
IRuntimeClasspathEntryResolver

computeUnresolvedRuntimeClasspath

public static IRuntimeClasspathEntry[] computeUnresolvedRuntimeClasspath(ILaunchConfiguration configuration)
                                                                  throws CoreException
Computes and returns the unresolved class path for the given launch configuration. Variable and container entries are unresolved.

Parameters:
configuration - launch configuration
Returns:
unresolved runtime classpath entries
Throws:
CoreException - if unable to compute the classpath
Since:
2.0

resolveRuntimeClasspath

public static IRuntimeClasspathEntry[] resolveRuntimeClasspath(IRuntimeClasspathEntry[] entries,
                                                               ILaunchConfiguration configuration)
                                                        throws CoreException
Resolves the given classpath, returning the resolved classpath in the context of the given launch configuration.

Parameters:
entries - unresolved classpath
configuration - launch configuration
Returns:
resolved runtime classpath entries
Throws:
CoreException - if unable to compute the classpath
Since:
2.0

getJavaProject

public static IJavaProject getJavaProject(ILaunchConfiguration configuration)
                                   throws CoreException
Return the IJavaProject referenced in the specified configuration or null if none.

Throws:
CoreException - if the referenced Java project does not exist
Since:
2.0

computeVMInstall

public static IVMInstall computeVMInstall(ILaunchConfiguration configuration)
                                   throws CoreException
Returns the VM install for the given launch configuration. The VM install is determined in the following prioritized way:
  1. The VM install is explicitly specified on the launch configuration via the ATTR_VM_INSTALL_TYPE and ATTR_VM_INSTALL_ID attributes.
  2. If no explicit VM install is specified, the VM install associated with the launch confiugration's project is returned.
  3. If no project is specified, or the project does not specify a custom VM install, the workspace default VM install is returned.

Parameters:
configuration - launch configuration
Returns:
vm install
Throws:
CoreException - if unable to compute a vm install
Since:
2.0

computeDefaultRuntimeClassPath

public static String[] computeDefaultRuntimeClassPath(IJavaProject jproject)
                                               throws CoreException
Computes the default application classpath entries for the given project.

Parameters:
jproject - The project to compute the classpath for
Returns:
The computed classpath. May be empty, but not null.
Throws:
CoreException - if unable to compute the default classpath

saveVMConfiguration

public static void saveVMConfiguration()
                                throws CoreException
Saves the VM configuration information to disk. This includes the following information:

getLibraryLocations

public static LibraryLocation[] getLibraryLocations(IVMInstall vm)
Evaluates library locations for a IVMInstall. If no library locations are set on the install, a default location is evaluated and checked if it exists.

Returns:
library locations with paths that exist or are empty
Since:
2.0

getJREVariableEntry

public static IClasspathEntry getJREVariableEntry()
Creates and returns a classpath entry describing the JRE_LIB classpath variable.

Returns:
a new IClasspathEntry that describes the JRE_LIB classpath variable

getDefaultJREContainerEntry

public static IClasspathEntry getDefaultJREContainerEntry()
Creates and returns a classpath entry describing the default JRE container entry.

Returns:
a new IClasspathEntry that describes the default JRE container entry
Since:
2.0

getVMConnector

public static IVMConnector getVMConnector(String id)
Returns the VM connetor defined with the specified identifier, or null if none.

Parameters:
id - VM connector identifier
Returns:
VM connector or null if none
Since:
2.0

getVMConnectors

public static IVMConnector[] getVMConnectors()
Returns all VM connector extensions.

Returns:
VM connectors
Since:
2.0

getPreferences

public static Preferences getPreferences()
Returns the preference store for the launching plug-in.

Returns:
the preference store for the launching plug-in
Since:
2.0

savePreferences

public static void savePreferences()
Saves the preferences for the launching plug-in.

Since:
2.0

addVariableResolver

public static void addVariableResolver(IRuntimeClasspathEntryResolver resolver,
                                       String variableName)
Registers the given resolver for the specified variable.

Parameters:
resolver - runtime classpathe entry resolver
variableName - variable name to register for
Since:
2.0

addContainerResolver

public static void addContainerResolver(IRuntimeClasspathEntryResolver resolver,
                                        String containerIdentifier)
Registers the given resolver for the specified container.

Parameters:
resolver - runtime classpathe entry resolver
containerIdentifier - identifier of the classpath container to register for
Since:
2.0

addVMInstallChangedListener

public static void addVMInstallChangedListener(IVMInstallChangedListener listener)
Adds the given listener to the list of registered VM install changed listeners. Has no effect if an identical listener is already registered.

Parameters:
listener - the listener to add
Since:
2.0

removeVMInstallChangedListener

public static void removeVMInstallChangedListener(IVMInstallChangedListener listener)
Removes the given listener from the list of registered VM install changed listeners. Has no effect if an identical listener is not already registered.

Parameters:
listener - the listener to remove
Since:
2.0

fireVMChanged

public static void fireVMChanged(PropertyChangeEvent event)
Notifies all VM install changed listeners of the given property change.

Parameters:
event - event desribing the change.
Since:
2.0

fireVMAdded

public static void fireVMAdded(IVMInstall vm)
Notifies all VM install changed listeners of the VM addition

Parameters:
vm - the VM that has been added
Since:
2.0

fireVMRemoved

public static void fireVMRemoved(IVMInstall vm)
Notifies all VM install changed listeners of the VM removal

Parameters:
vm - the VM that has been removed
Since:
2.0

Eclipse JDT
2.0

Copyright (c) IBM Corp. and others 2000, 2002. All Rights Reserved.