Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can get the actual classpath from the classloader. this must include the jar file, otherwise the program wouldn't run. Look throug the classpath URLs to find a URL that ends with ".jar" and contains something that is never changing in the name of you jar file (preferably after the last "/"). After that you open it as a regular jar (or zip) file and read the contents. </p> <p>There are several methods available for obtaining the classpath. None of them works in every context and with every setup, so you must try them one by one until you find one that works in all the situations you need it to work. Also, sometimes you might need to tweak the runtime context, like (often needed) substituting maven surefire-plugin's classloading mechanism to one of optional (non-default) ones. </p> <p>Obtaining the classpath 1: from system property:</p> <pre><code>static String[] getClasspathFromProperty() { return System.getProperty("java.class.path").split(File.pathSeparator); } </code></pre> <p>Obtaining the classpath 2: from classloader (with maven warning):</p> <pre><code>String[] getClasspathFromClassloader() { URLClassLoader classLoader = (URLClassLoader) (getClass().getClassLoader()); URL[] classpath = classLoader.getURLs(); if (classpath.length == 1 &amp;&amp; classpath[0].toExternalForm().indexOf("surefirebooter") &gt;= 0) { // todo: read classpath from manifest in surefireXXXX.jar System.err.println("NO PROPER CLASSLOADER HERE!"); System.err.println( "Run maven with -Dsurefire.useSystemClassLoader=false " +"-Dsurefire.useManifestOnlyJar=false to enable proper classloaders"); return null; } String[] classpathLocations = new String[classpath.length]; for (int i = 0; i &lt; classpath.length; i++) { // you must repair the path strings: "\.\" =&gt; "/" etc. classpathLocations[i] = cleanClasspathUrl(classpath[i].toExternalform()); } return classpathLocations; } </code></pre> <p>Obtaining the classpath 3: from current thread context: This is similar to method 2, except the first line of the method should read like this:</p> <pre><code> URLClassLoader classLoader = (URLClassLoader)(Thread.currentThread().getContextClassLoader()); </code></pre> <p>Good luck!</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. 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