I'm trying to run a project in Eclipse Indigo where my main class (containing the main method) is in an external .jar file I created from another project. The program is run based upon passing the name of a class in the current project to the main method as a command line argument.
When I try to run this project, the first few lines of the main method (in the .jar) are executed, but then the program exits. The debugger has informed me that it exits with an error code of 1. No exceptions are thrown (or at least, none appear in the console or in my try-catch blocks) and I make no assertion statements of calls to System.exit
.
When run directly, the main method complete's normally. This unexpected exit occurs only when the project is exported to a .jar.
I find this exceptionally confusing, especially considering that debugging has confirmed that the main method is called, and simply quits near the end without completing. Here is my main method:
public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, SecurityException
{
Class<?> c = Class.forName(args[0]);
OpenGL.Renderer r = null;
Class<? extends OpenGL.Renderer> c2 = c.asSubclass(OpenGL.Renderer.class);
r = c2.newInstance();
OpenGL.init(r);
}
The debugger reaches the breakpoint at line 16 (r = c2.newInstance()
) before terminating.
EDIT: The problem appears to lie with the reflection code that initializes the variable r
. No matter where I put my breakpoints I can't step to a situation in which r is not null.
EDIT #2: After using the debugger some more, I can step into the constructor being called in the c2.newInstance()
call, but the program exits immediately after method entry, before any of the constructor is executed. The constructor doesn't contain anything other than a syso call for debugging.
Any help in getting this program to run correctly would be appreciated.