Java – How to know if is Applet or Application

appletjavajava-native-interface

I have this code inside a class that is used by an application and by an applet.

static
{
    if (System.getProperty("os.name").startsWith("Windows"))
    {
        System.loadLibrary("extmapi");
    }
}

Unfortunately, when the applet loads this code I get an error, because it can't load the "extmapi" library.

To avoid this error, I need to know if the code I'm running is an Applet or an application, so that I can do:

if (isApplet)
    return;
else
    //load library

How can I know if I'm running inside an Applet?

Best Answer

Can't you just catch the (Security?) exception?