diff --git a/netx/net/sourceforge/jnlp/Launcher.java b/netx/net/sourceforge/jnlp/Launcher.java
--- a/netx/net/sourceforge/jnlp/Launcher.java
+++ b/netx/net/sourceforge/jnlp/Launcher.java
@@ -582,6 +582,12 @@
                 }
             });
 
+            if (context) {
+                Thread.currentThread().setContextClassLoader(app.getClassLoader());
+                SunToolkit.createNewAppContext();
+                doPerApplicationAppContextHacks();
+            }
+
             setContextClassLoaderForAllThreads(app.getThreadGroup(), app.getClassLoader());
 
             handler.launchStarting(app);
@@ -648,12 +654,12 @@
      * @param file the JNLP file
      * @param enableCodeBase whether to add the codebase URL to the classloader
      */
-    protected ApplicationInstance launchApplet(JNLPFile file, boolean enableCodeBase, Container cont) throws LaunchException {
+    protected ApplicationInstance launchApplet(JNLPFile file, boolean enableCodeBase, Container cont, boolean isPlugin) throws LaunchException {
         if (!file.isApplet())
             throw launchError(new LaunchException(file, null, R("LSFatal"), R("LCClient"), R("LNotApplet"), R("LNotAppletInfo")));
 
         try {
-            AppletInstance applet = createApplet(file, enableCodeBase, cont);
+            AppletInstance applet = createApplet(file, enableCodeBase, cont, isPlugin);
             applet.initialize();
 
             applet.getAppletEnvironment().startApplet(); // this should be a direct call to applet instance
@@ -668,12 +674,12 @@
     /**
      * Gets an ApplicationInstance, but does not launch the applet.
      */
-    protected ApplicationInstance getApplet(JNLPFile file, boolean enableCodeBase, Container cont) throws LaunchException {
+    protected ApplicationInstance getApplet(JNLPFile file, boolean enableCodeBase, Container cont, boolean isPlugin) throws LaunchException {
         if (!file.isApplet())
             throw launchError(new LaunchException(file, null, R("LSFatal"), R("LCClient"), R("LNotApplet"), R("LNotAppletInfo")));
 
         try {
-            AppletInstance applet = createApplet(file, enableCodeBase, cont);
+            AppletInstance applet = createApplet(file, enableCodeBase, cont, isPlugin);
             applet.initialize();
             return applet;
         } catch (LaunchException lex) {
@@ -696,10 +702,20 @@
      *
      * @param enableCodeBase whether to add the code base URL to the classloader
      */
-    protected AppletInstance createApplet(JNLPFile file, boolean enableCodeBase, Container cont) throws LaunchException {
+    protected AppletInstance createApplet(JNLPFile file, boolean enableCodeBase, Container cont, boolean isPlugin) throws LaunchException {
         try {
             JNLPClassLoader loader = JNLPClassLoader.getInstance(file, updatePolicy);
 
+            // Do not create new AppContext if we're using NetX and icedteaplugin.
+            // The plugin needs an AppContext too, but it has to be created earlier.
+            if (context) {
+                if (!isPlugin) {
+                    Thread.currentThread().setContextClassLoader(loader);
+                    SunToolkit.createNewAppContext();
+                }
+                doPerApplicationAppContextHacks();
+            }
+
             if (enableCodeBase) {
                 loader.enableCodeBase();
             } else if (file.getResources().getJARs().length == 0) {
@@ -873,22 +889,16 @@
 
         public void run() {
             try {
-                // Do not create new AppContext if we're using NetX and icedteaplugin.
-                // The plugin needs an AppContext too, but it has to be created earlier.
-                if (context && !isPlugin)
-                    SunToolkit.createNewAppContext();
-
-                doPerApplicationAppContextHacks();
 
                 if (isPlugin) {
                     // Do not display download indicators if we're using gcjwebplugin.
                     JNLPRuntime.setDefaultDownloadIndicator(null);
-                    application = getApplet(file, ((PluginBridge)file).codeBaseLookup(), cont);
+                    application = getApplet(file, ((PluginBridge)file).codeBaseLookup(), cont, isPlugin);
                 } else {
                     if (file.isApplication())
                         application = launchApplication(file);
                     else if (file.isApplet())
-                        application = launchApplet(file, true, cont); // enable applet code base
+                        application = launchApplet(file, true, cont, isPlugin); // enable applet code base
                     else if (file.isInstaller())
                         application = launchInstaller(file);
                     else