Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

loader

Java Class Loader


Description

.jaddClassPath adds directories or JAR files to the class path.

.jclassPath returns a vector containing the current entries in the class path

Usage

.jaddClassPath(path, class.loader=.rJava.class.loader)
.jclassPath(class.loader=.rJava.class.loader)
.jclassLoader(package=NULL)

Arguments

path

character string vector listing the paths to add to the class path

class.loader

Java class loader to use for the query of madification. Defaults to global class loader.

package

string, name of a package or NULL for the global class loader

Details

Whenever a class needs to be instantiated in Java it is referred by name which is used to locate a file with the bytecode for the class. The mechanism to map a name to an actual bytecode to load ind instantiate is habdled by the Java class loader. It typically keeps a list of directories and JAR files to search for the class names.

The .jaddClassPath() function allows the user to append new locations to the list of places which will be searched. The function .jclassPath retrieves the current sarch list from the loader.

When rJava is initialized, it instantiates the global class loader which is responsible for finding classes in functions such as .jnew(). In addition to the global class loader, R packages can create their own class loaders to avoid conflicts between packages such that they can be sure to use their own files to look for classes. See .jpackage for details on how that works. If the package argument is supplied .jclassLoader will look in that package to see if it has a custom loader and will return it, otherwise it returns the global loader. Note that is will fail with an error when supplied a non-existing package name.

If you want to trace issues related to missing classes, you can enable debugging in the class loader by using the setDebug method, for example: .jclassLoader()$setDebug(1L)

Value

.jclassPath returns a character vector listing the class path sequence.

See Also

Examples

## Not run: 
.jaddClassPath("/my/jars/foo.jar","/my/classes/")
print(.jclassPath())

## End(Not run)

rJava

Low-Level R to Java Interface

v1.0-4
LGPL-2.1
Authors
Simon Urbanek <simon.urbanek@r-project.org>
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.