Package org.apache.groovy.util

# Class JavaShell

java.lang.Object
org.apache.groovy.util.JavaShell

@Incubating public class JavaShell extends Object
A shell for compiling or running pure Java code

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `JavaShell()`
  Initializes a newly created `JavaShell` object
  `JavaShell(ClassLoader parentClassLoader)`
  Initializes a newly created `JavaShell` object

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Class<?>`
  `compile(String className, Iterable<String> options, String src)`
  Compile and return the main class
  `Class<?>`
  `compile(String className, String src)`
  Compile and return the main class
  `Map<String,Class<?>>`
  `compileAll(String className, Iterable<String> options, String src)`
  Compile and return all classes
  `Map<String,Class<?>>`
  `compileAll(String className, String src)`
  Compile and return all classes
  `org.apache.groovy.util.JavaShell.JavaShellClassLoader`
  `getClassLoader()`
  When and only when `compile(String, String)` or `compileAll(String, String)` is invoked, returned class loader will reference the compiled classes.
  `void`
  `run(String className, Iterable<String> options, String src, String... args)`
  Run main method
  `void`
  `run(String className, String src, String... args)`
  Run main method

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### JavaShell

    public JavaShell()
    Initializes a newly created `JavaShell` object

  - ### JavaShell

    public JavaShell(ClassLoader parentClassLoader)
    Initializes a newly created `JavaShell` object
    Parameters:
      `parentClassLoader` - the parent class loader for delegation

- ## Method Details

  - ### run

    public void run(String className, Iterable<String> options, String src, String... args) throws Throwable
    Run main method
    Parameters:
      `className` - the main class name
      `options` - compiler options
      `src` - the source code
      `args` - arguments for main method
    Throws:
      `Throwable`

  - ### run

    public void run(String className, String src, String... args) throws Throwable
    Run main method
    Parameters:
      `className` - the main class name
      `src` - the source code
      `args` - arguments for main method
    Throws:
      `Throwable`

  - ### compile

    public Class<?> compile(String className, Iterable<String> options, String src) throws IOException, ClassNotFoundException
    Compile and return the main class
    Parameters:
      `className` - the main class name
      `options` - compiler options
      `src` - the source code
    Returns:
      the main class
    Throws:
      `IOException`
      `ClassNotFoundException`

  - ### compile

    public Class<?> compile(String className, String src) throws IOException, ClassNotFoundException
    Compile and return the main class
    Parameters:
      `className` - the main class name
      `src` - the source code
    Returns:
      the main class
    Throws:
      `IOException`
      `ClassNotFoundException`

  - ### compileAll

    public Map<String,Class<?>> compileAll(String className, Iterable<String> options, String src) throws IOException, ClassNotFoundException
    Compile and return all classes
    Parameters:
      `className` - the main class name
      `options` - compiler options
      `src` - the source code
    Returns:
      all classes
    Throws:
      `IOException`
      `ClassNotFoundException`

  - ### compileAll

    public Map<String,Class<?>> compileAll(String className, String src) throws IOException, ClassNotFoundException
    Compile and return all classes
    Parameters:
      `className` - the main class name
      `src` - the source code
    Returns:
      all classes
    Throws:
      `IOException`
      `ClassNotFoundException`

  - ### getClassLoader

    public org.apache.groovy.util.JavaShell.JavaShellClassLoader getClassLoader()
    When and only when `compile(String, String)` or `compileAll(String, String)` is invoked, returned class loader will reference the compiled classes.