groovy.lang.GroovyClassLoader.addClasspath()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(251)

本文整理了Java中groovy.lang.GroovyClassLoader.addClasspath()方法的一些代码示例,展示了GroovyClassLoader.addClasspath()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GroovyClassLoader.addClasspath()方法的具体详情如下:
包路径:groovy.lang.GroovyClassLoader
类名称:GroovyClassLoader
方法名:addClasspath

GroovyClassLoader.addClasspath介绍

[英]adds a classpath to this classloader.
[中]

代码示例

代码示例来源:origin: apache/groovy

/**
 * Adds the class paths (if any)
 *
 * @param classLoader the classloader to configure
 */
protected void addClassPathes(final GroovyClassLoader classLoader) {
  if (classpath != null) {
    for (int i = 0; i < classpath.list().length; i++) {
      classLoader.addClasspath(classpath.list()[i]);
    }
  }
}

代码示例来源:origin: org.codehaus.groovy/groovy

public void addClasspath(String path) {
  delegate.addClasspath(path);
}

代码示例来源:origin: apache/groovy

private void loadRegisteredScriptExtensions() {
    if (scriptExtensions.isEmpty()) {

      scriptExtensions.add(getScriptExtension().substring(2)); // first extension will be the one set explicitly on <groovyc>

      Path classpath = getClasspath() != null ? getClasspath() : new Path(getProject());
      final String[] pe = classpath.list();
      try (GroovyClassLoader loader = new GroovyClassLoader(getClass().getClassLoader())) {
        for (String file : pe) {
          loader.addClasspath(file);
        }
        scriptExtensions.addAll(SourceExtensionHandler.getRegisteredExtensions(loader));
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    }
  }
}

代码示例来源:origin: org.codehaus.groovy/groovy

public void configure(CompilerConfiguration configuration) {
  super.configure(configuration);
  // GroovyClassLoader should be able to find classes compiled from java sources
  File targetDir = configuration.getTargetDirectory();
  if (targetDir != null) {
    final String classOutput = targetDir.getAbsolutePath();
    getClassLoader().addClasspath(classOutput);
  }
}

代码示例来源:origin: org.codehaus.groovy/groovy

if (toolsJar.exists()) {
  GroovyClassLoader loader = cu.getClassLoader();
  loader.addClasspath(toolsJar.getAbsolutePath());
  return loader.loadClass(main);

代码示例来源:origin: org.codehaus.groovy/groovy

@Override
public void configure(final CompilerConfiguration config) {
  super.configure(config);
  // GroovyClassLoader should be able to find classes compiled from java sources
  File targetDir = config.getTargetDirectory();
  if (targetDir != null) {
    final String classOutput = targetDir.getAbsolutePath();
    getClassLoader().addClasspath(classOutput);
  }
}

代码示例来源:origin: org.codehaus.groovy/groovy

/**
 * creates a GroovyClassLoader.
 *
 * @param parent                    the parent class loader
 * @param config                    the compiler configuration
 * @param useConfigurationClasspath determines if the configurations classpath should be added
 */
public GroovyClassLoader(ClassLoader parent, CompilerConfiguration config, boolean useConfigurationClasspath) {
  super(EMPTY_URL_ARRAY, parent);
  if (config == null) config = CompilerConfiguration.DEFAULT;
  this.config = config;
  if (useConfigurationClasspath) {
    for (String path : config.getClasspath()) {
      this.addClasspath(path);
    }
  }
  initSourceEncoding(config);
}

代码示例来源:origin: apache/groovy

protected GroovyClassLoader createClassLoader() {
  GroovyClassLoader gcl =
      AccessController.doPrivileged(
          new PrivilegedAction<GroovyClassLoader>() {
            @Override
            public GroovyClassLoader run() {
              return new GroovyClassLoader(ClassLoader.getSystemClassLoader(), config);
            }
          });
  Path path = getClasspath();
  if (path != null) {
    final String[] filePaths = path.list();
    for (int i = 0; i < filePaths.length; i++) {
      String filePath = filePaths[i];
      gcl.addClasspath(filePath);
    }
  }
  return gcl;
}

代码示例来源:origin: apache/nifi

throw new ProcessException("Path not found `" + fcp + "` for `" + ADD_CLASSPATH.getDisplayName() + "`");
  shell.getClassLoader().addClasspath(fcp.toString());
shell.getClassLoader().addClasspath(groovyClasspath);

代码示例来源:origin: wiztools/rest-client

File[] dependencies = ConfigUtil.getTestDependencies();
for(File dependency: dependencies) {
  gcl.addClasspath(dependency.getAbsolutePath());

代码示例来源:origin: groovy/groovy-core

System.out.println("Iter " + i);
final GroovyClassLoader groovyLoader = new GroovyClassLoader ();
groovyLoader.addClasspath(path);

代码示例来源:origin: palantir/atlasdb

private void evalFiles(String[] filepaths, CommandLine cli) throws CompilationFailedException, IOException {
  Binding binding = setupBinding(new Binding(), cli.hasOption(MUTATIONS_ENABLED_FLAG_SHORT));
  GroovyShell shell = new GroovyShell(binding);
  if(cli.hasOption(CLASSPATH_FLAG_SHORT)) {
    shell.getClassLoader().addClasspath(cli.getOptionValue(CLASSPATH_FLAG_SHORT));
  }
  for(String filepath : filepaths) {
    File file = new File(filepath);
    shell.evaluate(file);
  }
}

代码示例来源:origin: stackoverflow.com

import groovy.lang.GroovyClassLoader;

public class MyClass {
  public static void main(String... args) {
    GroovyClassLoader groovyClassLoader = new GroovyClassLoader();

    // add "lib" to the classpath
    groovyClassLoader.addClasspath("lib");

    String groovyFile = "GroovyFile.groovy";
    Class parsedClass = groovyClassLoader.parseClass(groovyFile);
    System.out.println("class is " + parsedClass.toString());
  }
}

代码示例来源:origin: getheimdall/heimdall

/**
* Returns a {@link GroovyClassLoader} created from a reference path.
* 
* @return                    {@link GroovyClassLoader}
*/
private GroovyClassLoader loadClassPath() {
  classLoader = new GroovyClassLoader();
  File lastModifiedFile = lastModified((dir, name) -> name.contains(JAR));
  if (lastModifiedFile != null)
     classLoader.addClasspath(pathReferences + File.separator + lastModifiedFile.getName());
  
  return classLoader;
}

代码示例来源:origin: org.codehaus.groovy/groovy-jdk14

/**
 * Adds the class pathes (if any)
 *
 * @param classLoader the classloader to configure
 */
protected void addClassPathes(final GroovyClassLoader classLoader) {
  if (classpath != null) {
    for (int i = 0; i < classpath.list().length; i++) {
      classLoader.addClasspath(classpath.list()[i]);
    }
  }
}

代码示例来源:origin: org.kohsuke.droovy/groovy

/**
 * Adds the class pathes (if any)
 *
 * @param classLoader the classloader to configure
 */
protected void addClassPathes(final GroovyClassLoader classLoader) {
  if (classpath != null) {
    for (int i = 0; i < classpath.list().length; i++) {
      classLoader.addClasspath(classpath.list()[i]);
    }
  }
}

代码示例来源:origin: com.thinkaurelius.groovy-shaded-asm/groovy-shaded-asm

@Override
public void configure(final CompilerConfiguration config) {
  super.configure(config);
  // GroovyClassLoader should be able to find classes compiled from java sources
  File targetDir = config.getTargetDirectory();
  if (targetDir != null) {
    final String classOutput = targetDir.getAbsolutePath();
    getClassLoader().addClasspath(classOutput);
  }
}

代码示例来源:origin: org.codehaus.gmaven.runtime/gmaven-runtime-1.7

@Override
public void configure(final CompilerConfiguration config) {
  super.configure(config);
  // GroovyClassLoader should be able to find classes compiled from java sources
  File targetDir = config.getTargetDirectory();
  if (targetDir != null) {
    final String classOutput = targetDir.getAbsolutePath();
    getClassLoader().addClasspath(classOutput);
  }
}

代码示例来源:origin: com.thinkaurelius.groovy-shaded-asm/groovy-shaded-asm

protected GroovyClassLoader createClassLoader() {
  ClassLoader parent = ClassLoader.getSystemClassLoader();
  GroovyClassLoader gcl = new GroovyClassLoader(parent, config);
  Path path = getClasspath();
  if (path != null) {
    final String[] filePaths = path.list();
    for (int i = 0; i < filePaths.length; i++) {
      String filePath = filePaths[i];
      gcl.addClasspath(filePath);
    }
  }
  return gcl;
}

代码示例来源:origin: bonitasoft/bonita-engine

@Override
public void start() throws SBonitaException {
  groovyClassLoader = new GroovyClassLoader(classLoaderService.getLocalClassLoader(ScopeType.TENANT.name(), tenantId));
  groovyClassLoader.setShouldRecompile(true);
  try {
    final File folder = getBonitaHomeServer().getSecurityScriptsFolder(tenantId);
    groovyClassLoader.addClasspath(folder.getAbsolutePath());
  } catch (BonitaHomeNotSetException | IOException e) {
    throw new SExecutionException(e);
  }
}

相关文章