Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Put example-library.jar somewhere in your file system and pass that location to the code that runs JavaCompiler (the -classpath option). If you use an exploded WAR file to deploy, you can of course point it to the physical location within the WEB-INF/lib folder. The point is that you only need one configurable parameter in your webapp to do this, which can be a properties file entry, -D system property, database row or something else entirely.</p> <p>Sample code (tested in Tomcat 7 and OpenJDK 1.7 on Fedora 18 x64):</p> <pre><code>private File compile(File javaFile, String classpath) throws IOException { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null); Iterable&lt;? extends JavaFileObject&gt; compilationUnit = fileManager.getJavaFileObjects(javaFile); List&lt;String&gt; options = classpath != null ? Arrays.asList("-classpath", classpath) : null; StringWriter output = new StringWriter(); try { boolean successful = compiler.getTask(output, fileManager, null, options, null, compilationUnit).call(); if (!successful) { throw new CompilationException("Failed to compile: " + javaFile, output.toString()); } return firstClassFileFrom(javaFile.getParentFile()); } finally { fileManager.close(); } } private File firstClassFileFrom(File directory) { return directory.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.endsWith(".class"); } })[0]; } </code></pre> <p>See <a href="https://github.com/jpalomaki/compiler" rel="nofollow">https://github.com/jpalomaki/compiler</a> for a runnable sample webapp.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload