mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 06:05:01 +07:00
When running ant, prefer Main class over Launcher because IDEA builds all the necessary classpath on its own. Otherwise, with Launcher, weird problems possible because of screwed up class-loading (IDEA-105828 Ant javac fails with org.apache.tools.ant.taskdefs.Javac was not found with JAXB 2.2.7, works outside of IDEA)
This commit is contained in:
@@ -21,20 +21,25 @@ public final class AntMain2 {
|
||||
|
||||
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});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user