Search in sources :

Example 1 with JavaFXLibraryFatalException

use of javafxlibrary.exceptions.JavaFXLibraryFatalException in project JavaFXLibrary by eficode.

the class ApplicationLauncher method setToClasspath.

@RobotKeyword("Loads given path to classpath.\n\n" + "``path`` is the path to add.\n\n" + "If directory path has asterisk(*) after directory separator all jar files are added from directory.\n" + "\nExample:\n" + "| Set To Classpath | C:${/}users${/}my${/}test${/}folder | \n" + "| Set To Classpath | C:${/}users${/}my${/}test${/}folder${/}* | \n")
@ArgumentNames({ "path" })
public void setToClasspath(String path) {
    if (path.endsWith("*")) {
        path = path.substring(0, path.length() - 1);
        HelperFunctions.robotLog("INFO", "Adding all jars from directory: " + path);
        try {
            File directory = new File(path);
            File[] fileList = directory.listFiles();
            for (File file : fileList) {
                if (file.getName().endsWith(".jar"))
                    _addPathToClassPath(file.getAbsolutePath());
            }
        } catch (NullPointerException e) {
            throw new JavaFXLibraryFatalException("Directory not found: " + path + "\n" + e.getMessage(), e);
        }
    } else {
        _addPathToClassPath(path);
    }
}
Also used : JavaFXLibraryFatalException(javafxlibrary.exceptions.JavaFXLibraryFatalException) File(java.io.File) RobotKeyword(org.robotframework.javalib.annotation.RobotKeyword) ArgumentNames(org.robotframework.javalib.annotation.ArgumentNames)

Example 2 with JavaFXLibraryFatalException

use of javafxlibrary.exceptions.JavaFXLibraryFatalException in project JavaFXLibrary by eficode.

the class ApplicationLauncher method _addPathToClassPath.

private void _addPathToClassPath(String path) {
    URLClassLoader classLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
    HelperFunctions.robotLog("INFO", "Setting following path to Classpath: " + path);
    try {
        Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
        method.setAccessible(true);
        method.invoke(classLoader, (new File(path)).toURI().toURL());
    } catch (Exception e) {
        throw new JavaFXLibraryFatalException("Problem setting the classpath: " + path, e);
    }
}
Also used : URLClassLoader(java.net.URLClassLoader) JavaFXLibraryFatalException(javafxlibrary.exceptions.JavaFXLibraryFatalException) Method(java.lang.reflect.Method) File(java.io.File) JavaFXLibraryNonFatalException(javafxlibrary.exceptions.JavaFXLibraryNonFatalException) JavaFXLibraryFatalException(javafxlibrary.exceptions.JavaFXLibraryFatalException)

Aggregations

File (java.io.File)2 JavaFXLibraryFatalException (javafxlibrary.exceptions.JavaFXLibraryFatalException)2 Method (java.lang.reflect.Method)1 URLClassLoader (java.net.URLClassLoader)1 JavaFXLibraryNonFatalException (javafxlibrary.exceptions.JavaFXLibraryNonFatalException)1 ArgumentNames (org.robotframework.javalib.annotation.ArgumentNames)1 RobotKeyword (org.robotframework.javalib.annotation.RobotKeyword)1