Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

strace or procmon equivalent for java

When I run a C++ program, and it says "unable to open file" but does not say what the filename is, I normally use strace (Linux) or procmon(Windows) to find out which file it is trying to open and where it is looking for it.

I can't do that with java programs because all this is controlled from the java vm. Some of the jars/classes I deal with have configuration files which are optional. Sometimes, it would be nice to know what these configuration files (like .css files for javafx programs) are called, especially when no errors are reported.

If I don't have access to the sources, for instance, when I am given a .jar or .class file, is there an equivalent of strace (Linux) or procmon (windows) for java or is it some combination of debug options that gets the java VM to list out what files it is trying to open or where it is looking for the files?

like image 820
cup Avatar asked Mar 10 '26 20:03

cup


2 Answers

After messing around a lot, it looks like it is back to strace.

strace -f java xxx | egrep openat 1> files.log 2>&1

Then look at the files.log. What I didn't appreciate was that java launches the executable as a different process. strace -f traces the forked processes as well.

openat is the call for opening files. There are lots opens on class, jar and .so files. Once those have been taken out, what you are left with is all the other files.

like image 79
cup Avatar answered Mar 12 '26 09:03

cup


try lsof in linux, which can list files open by the process if it what you looking for , or you can always attach JVM debugger. or if you know more about java class loader, you can use it to find out .

like image 30
user5616998 Avatar answered Mar 12 '26 09:03

user5616998



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!