简体   繁体   中英

How can I find out which shared libraries I need to run a Java class on Linux?

I want to know what shared libraries I need to have available when running a particular Java application. I know how to get the library list for the Java interpreter (ldd java) but the application then goes on to do things with GUIs and sockets from the standard Java API.

So basically I want to know if there's some way I can find out what shared libraries a standard Java class in rt.jar (such as java.io.Socket or javax.swing.JFrame) will load behind the scenes, short of exhaustive path testing.

TIA!

You could get the source code , links are on the left (just above "Groups"). Obviously, it'll vary by JDK. Assuming you want more then ldd java .

If the source is not available, then you could load the class via a custom ClassLoader and override loadClass() to report what classes are being loaded:

public class CustomClassLoader extends ClassLoader{
    public CustomClassLoader(ClassLoader parent) {
        super(parent);
    }

    @Override
    protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
        System.out.println(name);
        return super.loadClass(name, resolve);
    }

}

and then run the class you want with the JVM flag -Djava.system.class.loader=CustomClassLoader

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM