Skip to main content
added 29 characters in body
Source Link
WReach
  • 69.3k
  • 4
  • 165
  • 272

Update 2023-06-16: TheIt is reported that the following response no longer works when using Mathematica 13.2 on MacOS.

The following function can be used to recover the resource URL that contains a given class:

Needs["JLink`"]
InstallJava[];
LoadJavaClass["com.wolfram.jlink.JLinkClassLoader"];

classResourceUrl[className_] :=
  JavaBlock @ Module[{resourceName, loader}
  , resourceName = StringReplace[className, "."->"/"]~~".class"
  ; loader =
      com`wolfram`jlink`JLinkClassLoader`classFromName[className] @ getClassLoader[] /.
        Null :> com`wolfram`jlink`JLinkClassLoaderHelper`getSystemClassLoader[]
  ; loader@getResource[resourceName] /. url:Except[Null] :> url@toString[]
  ]

It works by:

  1. Using JLinkClassLoader to recover the Java class object.
  2. Getting the class' classloader (Null indicating the system classloader).
  3. Using that classloader to get the URL of the class' binary name.

Here it is in action:

classResourceUrl["org.hsqldb.jdbc.JDBCDriver"]

(* jar:file:/C:/Program%20Files/Wolfram%20Research/Mathematica/10.2/
   SystemFiles/Links/DatabaseLink/Java/hsqldb.jar!
   /org/hsqldb/jdbc/JDBCDriver.class *)

classResourceUrl["org.rosuda.JRI.Rengine"]

(* jar:file:/C:/Program%20Files/Wolfram%20Research/Mathematica/10.2/
   SystemFiles/Links/RLink/Java/JRI.jar!
   /org/rosuda/JRI/Rengine.class *)

AddToClassPath @ "C:\\eclipse\\plugins\\org.junit_4.10.0\\junit.jar";
classResourceUrl["org.junit.Assert"]

(* jar:file:/C:/eclipse/plugins/org.junit_4.10.0/junit.jar!
   /org/junit/Assert.class *)

Update 2023-06-16: The following response no longer works when using Mathematica 13.2.

The following function can be used to recover the resource URL that contains a given class:

Needs["JLink`"]
InstallJava[];
LoadJavaClass["com.wolfram.jlink.JLinkClassLoader"];

classResourceUrl[className_] :=
  JavaBlock @ Module[{resourceName, loader}
  , resourceName = StringReplace[className, "."->"/"]~~".class"
  ; loader =
      com`wolfram`jlink`JLinkClassLoader`classFromName[className] @ getClassLoader[] /.
        Null :> com`wolfram`jlink`JLinkClassLoaderHelper`getSystemClassLoader[]
  ; loader@getResource[resourceName] /. url:Except[Null] :> url@toString[]
  ]

It works by:

  1. Using JLinkClassLoader to recover the Java class object.
  2. Getting the class' classloader (Null indicating the system classloader).
  3. Using that classloader to get the URL of the class' binary name.

Here it is in action:

classResourceUrl["org.hsqldb.jdbc.JDBCDriver"]

(* jar:file:/C:/Program%20Files/Wolfram%20Research/Mathematica/10.2/
   SystemFiles/Links/DatabaseLink/Java/hsqldb.jar!
   /org/hsqldb/jdbc/JDBCDriver.class *)

classResourceUrl["org.rosuda.JRI.Rengine"]

(* jar:file:/C:/Program%20Files/Wolfram%20Research/Mathematica/10.2/
   SystemFiles/Links/RLink/Java/JRI.jar!
   /org/rosuda/JRI/Rengine.class *)

AddToClassPath @ "C:\\eclipse\\plugins\\org.junit_4.10.0\\junit.jar";
classResourceUrl["org.junit.Assert"]

(* jar:file:/C:/eclipse/plugins/org.junit_4.10.0/junit.jar!
   /org/junit/Assert.class *)

Update 2023-06-16: It is reported that the following response no longer works when using Mathematica 13.2 on MacOS.

The following function can be used to recover the resource URL that contains a given class:

Needs["JLink`"]
InstallJava[];
LoadJavaClass["com.wolfram.jlink.JLinkClassLoader"];

classResourceUrl[className_] :=
  JavaBlock @ Module[{resourceName, loader}
  , resourceName = StringReplace[className, "."->"/"]~~".class"
  ; loader =
      com`wolfram`jlink`JLinkClassLoader`classFromName[className] @ getClassLoader[] /.
        Null :> com`wolfram`jlink`JLinkClassLoaderHelper`getSystemClassLoader[]
  ; loader@getResource[resourceName] /. url:Except[Null] :> url@toString[]
  ]

It works by:

  1. Using JLinkClassLoader to recover the Java class object.
  2. Getting the class' classloader (Null indicating the system classloader).
  3. Using that classloader to get the URL of the class' binary name.

Here it is in action:

classResourceUrl["org.hsqldb.jdbc.JDBCDriver"]

(* jar:file:/C:/Program%20Files/Wolfram%20Research/Mathematica/10.2/
   SystemFiles/Links/DatabaseLink/Java/hsqldb.jar!
   /org/hsqldb/jdbc/JDBCDriver.class *)

classResourceUrl["org.rosuda.JRI.Rengine"]

(* jar:file:/C:/Program%20Files/Wolfram%20Research/Mathematica/10.2/
   SystemFiles/Links/RLink/Java/JRI.jar!
   /org/rosuda/JRI/Rengine.class *)

AddToClassPath @ "C:\\eclipse\\plugins\\org.junit_4.10.0\\junit.jar";
classResourceUrl["org.junit.Assert"]

(* jar:file:/C:/eclipse/plugins/org.junit_4.10.0/junit.jar!
   /org/junit/Assert.class *)
added disclaimer for version 13.2
Source Link
WReach
  • 69.3k
  • 4
  • 165
  • 272

Update 2023-06-16: The following response no longer works when using Mathematica 13.2.

The following function can be used to recover the resource URL that contains a given class:

Needs["JLink`"]
InstallJava[];
LoadJavaClass["com.wolfram.jlink.JLinkClassLoader"];

classResourceUrl[className_] :=
  JavaBlock @ Module[{resourceName, loader}
  , resourceName = StringReplace[className, "."->"/"]~~".class"
  ; loader =
      com`wolfram`jlink`JLinkClassLoader`classFromName[className] @ getClassLoader[] /.
        Null :> com`wolfram`jlink`JLinkClassLoaderHelper`getSystemClassLoader[]
  ; loader@getResource[resourceName] /. url:Except[Null] :> url@toString[]
  ]

It works by:

  1. Using JLinkClassLoader to recover the Java class object.
  2. Getting the class' classloader (Null indicating the system classloader).
  3. Using that classloader to get the URL of the class' binary name.

Here it is in action:

classResourceUrl["org.hsqldb.jdbc.JDBCDriver"]

(* jar:file:/C:/Program%20Files/Wolfram%20Research/Mathematica/10.2/
   SystemFiles/Links/DatabaseLink/Java/hsqldb.jar!
   /org/hsqldb/jdbc/JDBCDriver.class *)

classResourceUrl["org.rosuda.JRI.Rengine"]

(* jar:file:/C:/Program%20Files/Wolfram%20Research/Mathematica/10.2/
   SystemFiles/Links/RLink/Java/JRI.jar!
   /org/rosuda/JRI/Rengine.class *)

AddToClassPath @ "C:\\eclipse\\plugins\\org.junit_4.10.0\\junit.jar";
classResourceUrl["org.junit.Assert"]

(* jar:file:/C:/eclipse/plugins/org.junit_4.10.0/junit.jar!
   /org/junit/Assert.class *)

The following function can be used to recover the resource URL that contains a given class:

Needs["JLink`"]
InstallJava[];
LoadJavaClass["com.wolfram.jlink.JLinkClassLoader"];

classResourceUrl[className_] :=
  JavaBlock @ Module[{resourceName, loader}
  , resourceName = StringReplace[className, "."->"/"]~~".class"
  ; loader =
      com`wolfram`jlink`JLinkClassLoader`classFromName[className] @ getClassLoader[] /.
        Null :> com`wolfram`jlink`JLinkClassLoaderHelper`getSystemClassLoader[]
  ; loader@getResource[resourceName] /. url:Except[Null] :> url@toString[]
  ]

It works by:

  1. Using JLinkClassLoader to recover the Java class object.
  2. Getting the class' classloader (Null indicating the system classloader).
  3. Using that classloader to get the URL of the class' binary name.

Here it is in action:

classResourceUrl["org.hsqldb.jdbc.JDBCDriver"]

(* jar:file:/C:/Program%20Files/Wolfram%20Research/Mathematica/10.2/
   SystemFiles/Links/DatabaseLink/Java/hsqldb.jar!
   /org/hsqldb/jdbc/JDBCDriver.class *)

classResourceUrl["org.rosuda.JRI.Rengine"]

(* jar:file:/C:/Program%20Files/Wolfram%20Research/Mathematica/10.2/
   SystemFiles/Links/RLink/Java/JRI.jar!
   /org/rosuda/JRI/Rengine.class *)

AddToClassPath @ "C:\\eclipse\\plugins\\org.junit_4.10.0\\junit.jar";
classResourceUrl["org.junit.Assert"]

(* jar:file:/C:/eclipse/plugins/org.junit_4.10.0/junit.jar!
   /org/junit/Assert.class *)

Update 2023-06-16: The following response no longer works when using Mathematica 13.2.

The following function can be used to recover the resource URL that contains a given class:

Needs["JLink`"]
InstallJava[];
LoadJavaClass["com.wolfram.jlink.JLinkClassLoader"];

classResourceUrl[className_] :=
  JavaBlock @ Module[{resourceName, loader}
  , resourceName = StringReplace[className, "."->"/"]~~".class"
  ; loader =
      com`wolfram`jlink`JLinkClassLoader`classFromName[className] @ getClassLoader[] /.
        Null :> com`wolfram`jlink`JLinkClassLoaderHelper`getSystemClassLoader[]
  ; loader@getResource[resourceName] /. url:Except[Null] :> url@toString[]
  ]

It works by:

  1. Using JLinkClassLoader to recover the Java class object.
  2. Getting the class' classloader (Null indicating the system classloader).
  3. Using that classloader to get the URL of the class' binary name.

Here it is in action:

classResourceUrl["org.hsqldb.jdbc.JDBCDriver"]

(* jar:file:/C:/Program%20Files/Wolfram%20Research/Mathematica/10.2/
   SystemFiles/Links/DatabaseLink/Java/hsqldb.jar!
   /org/hsqldb/jdbc/JDBCDriver.class *)

classResourceUrl["org.rosuda.JRI.Rengine"]

(* jar:file:/C:/Program%20Files/Wolfram%20Research/Mathematica/10.2/
   SystemFiles/Links/RLink/Java/JRI.jar!
   /org/rosuda/JRI/Rengine.class *)

AddToClassPath @ "C:\\eclipse\\plugins\\org.junit_4.10.0\\junit.jar";
classResourceUrl["org.junit.Assert"]

(* jar:file:/C:/eclipse/plugins/org.junit_4.10.0/junit.jar!
   /org/junit/Assert.class *)
Source Link
WReach
  • 69.3k
  • 4
  • 165
  • 272

The following function can be used to recover the resource URL that contains a given class:

Needs["JLink`"]
InstallJava[];
LoadJavaClass["com.wolfram.jlink.JLinkClassLoader"];

classResourceUrl[className_] :=
  JavaBlock @ Module[{resourceName, loader}
  , resourceName = StringReplace[className, "."->"/"]~~".class"
  ; loader =
      com`wolfram`jlink`JLinkClassLoader`classFromName[className] @ getClassLoader[] /.
        Null :> com`wolfram`jlink`JLinkClassLoaderHelper`getSystemClassLoader[]
  ; loader@getResource[resourceName] /. url:Except[Null] :> url@toString[]
  ]

It works by:

  1. Using JLinkClassLoader to recover the Java class object.
  2. Getting the class' classloader (Null indicating the system classloader).
  3. Using that classloader to get the URL of the class' binary name.

Here it is in action:

classResourceUrl["org.hsqldb.jdbc.JDBCDriver"]

(* jar:file:/C:/Program%20Files/Wolfram%20Research/Mathematica/10.2/
   SystemFiles/Links/DatabaseLink/Java/hsqldb.jar!
   /org/hsqldb/jdbc/JDBCDriver.class *)

classResourceUrl["org.rosuda.JRI.Rengine"]

(* jar:file:/C:/Program%20Files/Wolfram%20Research/Mathematica/10.2/
   SystemFiles/Links/RLink/Java/JRI.jar!
   /org/rosuda/JRI/Rengine.class *)

AddToClassPath @ "C:\\eclipse\\plugins\\org.junit_4.10.0\\junit.jar";
classResourceUrl["org.junit.Assert"]

(* jar:file:/C:/eclipse/plugins/org.junit_4.10.0/junit.jar!
   /org/junit/Assert.class *)