Calling NetBeans Platform application from the command line
"karolinas" <[email protected]>
| Newsgroups | gmane.comp.java.netbeans.modules.openide.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi. I am launching my NetBeans Platform application from within another application calling it using ProcessBuilder. When using in it plain on its own it was working fine.
However, now I want to pass some extra arguments, ie. a project directory from where the NBP applications was launched so that it would automatically import some files to the project from that directory.
When I pass all the arguments in my CustomStartup class, it doesn't do anything, neither prints any errors nor starts the application, but then I tried passing the arguments minus the last one, and I got an error saying that "there are parameters but nobody wants to process them".
I specified to use my CustomStartup class as the main class in the .conf file, with the option
Code:
-J-Dnetbeans.mainclass=com.cmclinnovations.startup.CustomStartup
and added the jar file that wraps this custom class in the platform/core directory.
and my startup class is defined as follows:
Code:
public class CustomStartup {
private static final String NB_MAIN_CLASS = "org.netbeans.core.startup.Main";
public static void main(String[] args) throws Exception {
System.out.println("Arguments before: " + Arrays.asList(args));
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
Class<?> mainClass = Class.forName(NB_MAIN_CLASS, true, classloader);
Object mainObject = mainClass.newInstance();
Method mainMethod = mainClass.getDeclaredMethod("main", new Class[]{String[].class});
int size = args.length;
String[] args2 = new String[size - 1];
System.arraycopy(args, 0, args2, 0, size - 1);
System.out.println("Arguments after: " + Arrays.asList(args2));
mainMethod.invoke(mainObject, (Object) (args2));
}
}
I was thinking this was a way to go, but I cannot seem to make it work. Maybe there is another way to pass the command line arguments to the main method that I don't know about?