Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The main point is that, while a class loader loads classes, javac will call <code>JavaFileManager#list()</code> to get a listing of all the files in a package.</p> <p>So to use a custom class loader you need to modify (or extend) it to override <code>JavaFileManager#list()</code>. Hopefully you can reuse some of the logic used for class loading.</p> <p>You might want to use your own implementations of <code>JavaFileObject</code> to represent class objects. You will then need to override <code>JavaFileManager#inferBinaryName()</code> (else the javac version will crash). Your implementations of <code>JavaFileObject</code> also needs to override (at least) <code>JavaFileObject#openInputStream</code>.</p> <p>Here are some pointers: <a href="http://atamur.blogspot.be/2009/10/using-built-in-javacompiler-with-custom.html" rel="nofollow">http://atamur.blogspot.be/2009/10/using-built-in-javacompiler-with-custom.html</a></p> <p>Also, don't make your life harder than it should and extend <code>ForwardingJavaFileManager</code> and <code>SimpleJavaFileObject</code>.</p> <p>For reference, here is an example implementation:</p> <pre><code> @Override public Iterable&lt;JavaFileObject&gt; list(Location location, String packageName, Set&lt;JavaFileObject.Kind&gt; kinds, boolean recurse) throws IOException { Iterable&lt;JavaFileObject&gt; stdResults = fileManager.list(location, packageName, kinds, recurse); if (location != StandardLocation.CLASS_PATH || !kinds.contains(JavaFileObject.Kind.CLASS)) { return stdResults; } Set&lt;JavaFileObject&gt; additional = pkgObjects.get(packageName); if (additional == null || additional.isEmpty()) { return stdResults; } List&lt;JavaFileObject&gt; out = new ArrayList&lt;&gt;(); for (JavaFileObject obj : additional) { out.add(obj); } for (JavaFileObject obj : stdResults) { out.add(obj); } return out; } </code></pre> <p>Where <code>pkgObjects</code> is a map from package names to <code>JavaFileObject</code>. The way you fill this map depends on how your class loader works.</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. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    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