Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can do it in two ways:</p> <ol> <li>Rename your images, so you can enumerate them via some algorithm (e.g. <code>image_1</code>, <code>image_2</code>, <code>image_3</code>), then you can collect all resources you need in one go.</li> <li><p>Otherwise you need to code a lot. The idea is that you have to:</p> <ul> <li><p>determine the path to your JAR file:</p> <pre><code>private static final String ANCHOR_NAME = "some resource you know"; URL location = getClass().getClassLoader().getResource(ANCHOR_NAME); URL jarLocation; String protocol = location.getProtocol(); if (protocol.equalsIgnoreCase("jar")) { String path = location.getPath(); int index = path.lastIndexOf("!/" + ANCHOR_NAME); if(index != -1) jarLocation = new URL(path.substring(0, index)); } if (protocol.equalsIgnoreCase("file")) { String string = location.toString(); int index = string.lastIndexOf(ANCHOR_NAME); if(index != -1) jarLocation = new URL(string.substring(0, index)); } </code></pre></li> <li><p>open it as <code>java.util.jar.JarFile</code></p> <pre><code>JarFile jarFile = new JarFile(jarLocation); </code></pre></li> <li><p>iterate through all entries and match their name with a given mask</p> <pre><code>for (Enumeration entries = jarFile.entries(); entries.hasMoreElements();) { JarEntry entry = (JarEntry) entries.nextElement(); String entryPath = entry.getName(); if (entryPath.endsWith(".jpg")) { // do something with it } } </code></pre></li> </ul></li> </ol> <p>For additional code support, I will refer you to Spring <a href="http://www.jarvana.com/jarvana/view/org/springframework/spring-core/2.5.6/spring-core-2.5.6-sources.jar!/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java?format=ok" rel="nofollow noreferrer">PathMatchingResourcePatternResolver#doFindPathMatchingJarResources()</a>.</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.
    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