Snapshot e242282deb41c328afbe971fc167e47ddfb26df9 from master branch of git://git.jetbrains.org/idea/community.git

Change-Id: Ifdc1818cde7b63f6d7bf42801f18c7f1557b8d85
diff --git a/java/java-runtime/src/FormPreviewFrame.java b/java/java-runtime/src/FormPreviewFrame.java
index 939c468..5e69856 100644
--- a/java/java-runtime/src/FormPreviewFrame.java
+++ b/java/java-runtime/src/FormPreviewFrame.java
@@ -53,8 +53,10 @@
     }
 
     frame.pack();
-    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
-    frame.setLocation((screenSize.width - frame.getWidth())/2, (screenSize.height - frame.getHeight())/2);
+    Rectangle screenBounds =
+      GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getBounds();
+    frame.setLocation(screenBounds.x + (screenBounds.width - frame.getWidth()) / 2,
+                      screenBounds.y + (screenBounds.height - frame.getHeight()) / 2);
     frame.setVisible(true);
   }
 
diff --git a/java/java-runtime/src/com/intellij/rt/ant/execution/AntMain2.java b/java/java-runtime/src/com/intellij/rt/ant/execution/AntMain2.java
index 8b45dca..4e3b6c8 100644
--- a/java/java-runtime/src/com/intellij/rt/ant/execution/AntMain2.java
+++ b/java/java-runtime/src/com/intellij/rt/ant/execution/AntMain2.java
@@ -21,20 +21,25 @@
 
   public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
     IdeaAntLogger2.guardStreams();
-
-    // first try to use the new way of launching ant
+    
+    // as we build classpath ourselves, and ensure all libraries are added to classpath, 
+    // preferred way for us to run ant will be using the traditional ant entry point, via the "Main" class 
     try {
-      final Class antLauncher = Class.forName("org.apache.tools.ant.launch.Launcher");
+      final Class antMain = Class.forName("org.apache.tools.ant.Main");
       //noinspection HardCodedStringLiteral
-      antLauncher.getMethod("main", new Class[]{args.getClass()}).invoke(null, new Object[]{args});
+      antMain.getMethod("main", new Class[]{args.getClass()}).invoke(null, new Object[]{args});
       return;
     }
     catch (ClassNotFoundException e) {
-      // ignore and try older variant
+      // ignore
     }
-
-    final Class antMain = Class.forName("org.apache.tools.ant.Main");
+    
+    // fallback: try the newer approach, launcher
+    // This approach is less preferred in our case, but still...
+    // From the ant documentation: "You should start the launcher with the most minimal classpath possible, generally just the ant-launcher.jar."
+    final Class antLauncher = Class.forName("org.apache.tools.ant.launch.Launcher");
     //noinspection HardCodedStringLiteral
-    antMain.getMethod("main", new Class[]{args.getClass()}).invoke(null, new Object[]{args});
+    antLauncher.getMethod("main", new Class[]{args.getClass()}).invoke(null, new Object[]{args});
+
   }
 }