Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Found the answer:</p> <p><code>Play.application().resource()</code> doesn't work in <code>play dist</code> version, but <code>Play.application().resourceAsStream()</code> does. </p> <p>This will return the resource as a <code>InputStream</code>, not an <code>URL</code>. You'll have to find ways of using the InputStream in stead of the URL.</p> <p>One possibility could be to write the InputStream to a file, and then get the URL to the file.</p> <p>I wrote a JarClassLoader that handles InputStreams for loading classes (the jar files and the classes are loaded into memory):</p> <pre class="lang-java prettyprint-override"><code>public class JarClassLoader extends SecureClassLoader{ private Hashtable&lt;String, byte[]&gt; classes = new Hashtable&lt;&gt;(); private Hashtable&lt;String, Class&gt; loadedClasses = new Hashtable&lt;&gt;(); JarClassLoader(InputStream[] jarFiles, ClassLoader parent) { super(parent); try { for (InputStream jarFile : jarFiles) { JarInputStream jis = new JarInputStream(jarFile); JarEntry entry = jis.getNextJarEntry(); while(entry != null) { if (entry.getName().endsWith(".class")) { BufferedInputStream bis = new BufferedInputStream(jis); ByteArrayOutputStream baos = new ByteArrayOutputStream(); int bytes = bis.read(); while (bytes != -1) { baos.write(bytes); bytes = bis.read(); } classes.put(entry.getName().substring(0, entry.getName().length() - 6).replace("/", "."), baos.toByteArray()); } entry = jis.getNextJarEntry(); } } } catch (IOException e) { e.printStackTrace(); classes = null; } } @Override public Class loadClass(String name) throws ClassNotFoundException { if (loadedClasses.containsKey(name)) { return loadedClasses.get(name); } else if (classes.containsKey(name)) { byte[] classBytes = classes.get(name); Class clazz = defineClass(name, classBytes, 0, classBytes.length); loadedClasses.put(name, clazz); return clazz; } else { return super.loadClass(name); } } } </code></pre> <p>Now I'm able to use <code>Play.application().resourceAsStream()</code> like this:</p> <pre class="lang-java prettyprint-override"><code>private static final ClassLoader classloader = new JarClassLoader(new InputStream[]{ Play.application().resourceAsStream("path/to/file.jar") }, ThisClass.class.getClassLoader()); </code></pre>
    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. 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