How can I JNI FindClass in an classLoader applet running in another thread

  c++, java, java-native-interface, multithreading

I have a jar file acting as a launcher (launcher.jar), it has these two classes, they describe how the application starts. And the jar file of the application itself (applet.jar)

package mylauncher;
public class MyClassLoader
{
  private static ClassLoader classLoader;
  public MyClassLoader()
  {
...
  }
  public Applet createApplet()
    throws ClassNotFoundException, InstantiationException, IllegalAccessException
  {
    Class localClass = classLoader.loadClass("myapplet.MyApplet");
    return (Applet)localClass.newInstance();
  }
}

package mylauncher;
public class MyFrame extends Frame implements AppletStub
{
  public void start()
  {
    Thread localThread = new Thread() //<= i need FindClass in this thread in jni
    {
      public void run()
      {
        try
        {
          MyClassLoader localMyClassLoader = new MyClassLoader();
          MyFrame.this.replace(MyClassLoader.createApplet());
        }
...
      }
    };
    localThread.setDaemon(true);
    localThread.start();
  }
}

In C ++, I can find the class from the launcher, but I cannot from the application itself. How can I solve this problem?

            jclass jMyFrame = env->FindClass("mylauncher/MyFrame");
            std::cout << "MyFrame: " << jMyFrame << std::endl; //it's not empty
            jclass jMyApplet = env->FindClass("myapplet/MyApplet");
            std::cout << "MyApplet : " << jMyApplet << std::endl; //it's empty

Source: Windows Questions C++

LEAVE A COMMENT