The project I'm working on has about 10 jar files as libraries. At the top of one of the files there's an import statement like:
import jpe.nar.crat.maker.ObjectMakerFactory;
Is there a way to tell which Jar file it comes from?
(I'm using Netbeans if that matters.)
The, the idea is to use find on the root of your classpath to locate all jars, then runs findclass.sh on all found jars to look for a match. It doesn't handle multi-directories, but if you carefully choose the root you can get it to work.
It is often located in the "Program Files\Java" or "Program Files (x86)\Java" folder, within a possible subfolder below the Java folder. Once you find the file, select it and click OK.
The most common program Java Runtime Environment (JRE) is available to download for free for Windows and macOS operating systems from the Java website. After installing the program, run the . jar file by double-clicking on it.
All the compiled binaries loaded at JVM start up will be in JAVA_HOME\jre\lib or JAVA_HOME\jre\lib\ext .
You can use CodeSource#getLocation()
for this. The CodeSource
is available by ProtectionDomain#getCodeSource()
. The ProtectionDomain
in turn is available by Class#getProtectionDomain()
.
URL location = ObjectMakerFactory.class.getProtectionDomain().getCodeSource().getLocation();
System.out.println(location.getPath());
// ...
Have you tried doing a 'Open Declaration' on the class? In Eclipse, when you do it, it opens a window that shows the name of the jar and tells you that this jar has 'No Source Attachment'. I am hoping something similar should happen for NetBeans.
Thanks, R
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With