Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The <a href="http://java.sun.com/javase/6/docs/api/javax/tools/JavaCompiler.html#getTask%28java.io.Writer,%20javax.tools.JavaFileManager,%20javax.tools.DiagnosticListener,%20java.lang.Iterable,%20java.lang.Iterable,%20java.lang.Iterable%29" rel="noreferrer">javax.tools.JavaCompiler#getTask()</a> method takes an <code>options</code> parameter that allows to set compiler options. The following <a href="http://forums.sun.com/thread.jspa?messageID=10377161#10377161" rel="noreferrer">message</a> describes an easy way to set them in order to access the calling program's classpath:</p> <blockquote> <p>You need to configure the standard java file manager to know about the jar files(s) - you use the compiler options argument to do that.</p> <p>By default the java compiler object only seems to know about the default locations for bootclasspath, extdirs and endorseddirs directories in terms of its classpath.</p> <p><strong>You need to add the calling program's current classpath to the java compiler instance's which gets passed on the the standard file manager, which will then find classes in the jar files.</strong></p> <p>Here's how I do it in <a href="https://hickory.dev.java.net/source/browse/hickory/trunk/code/src/net/java/dev/hickory/testing/Compilation.java?rev=11&amp;view=markup" rel="noreferrer">the compiler wrapper I wrote</a> </p> <pre><code>List&lt;String&gt; optionList = new ArrayList&lt;String&gt;(); // set compiler's classpath to be same as the runtime's optionList.addAll(Arrays.asList("-classpath",System.getProperty("java.class.path"))); // any other options you want optionList.addAll(Arrays.asList(options)); JavaCompiler.CompilationTask task = compiler.getTask(out,jfm,diagnostics,optionList,null,jfos); </code></pre> </blockquote> <p>All you'll need then is to get the proper classpath set when running the calling program.</p>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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