How to run an eclipse workbench action
I am developing an eclipse plugin. I have declared an action set with one action, but when the action is invoked it isn't doing what it should.
Here is the class for the action.
package instantmes开发者_运维问答sengerplugin;
import java.io.IOException;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
public class ActionClass implements IWorkbenchWindowActionDelegate {
@Override
public void dispose() {
// TODO Auto-generated method stub
}
@Override
public void init(IWorkbenchWindow window) {
//this.window = window;
}
@Override
public void run(IAction arg0) {
System.out.println("hello");
Connection.main(null);
}
@Override
public void selectionChanged(IAction arg0, ISelection arg1) {
// TODO Auto-generated method stub
}
}
so I know that this class works okay because the print statement in the run method executes fine.
Connection is contained within a jar that I have added to the class path. It is present within the referenced libraries for the project. My goal is to have the action launch the jar file.
I have run the debugger on the Connection.main line.
Here is the stack for when I step into this line:
EventTable.sendEvent(Event) line: 87
ToolItem(Widget).sendEvent(Event) line: 1003
Display.runDeferredEvents() line: 3880
Display.readAndDispatch() line: 3473
Workbench.runEventLoop(Window$IExceptionHandler, Display) line: 2405
Workbench.runUI() line: 2369
Workbench.access$4(Workbench) line: 2221
Workbench$5.run() line: 500
Realm.runWithDefault(Realm, Runnable) line: 332
Workbench.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 493
PlatformUI.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 149
IDEApplication.start(IApplicationContext) line: 113
EclipseAppHandle.run(Object) line: 194
EclipseAppLauncher.runApplication(Object) line: 110
EclipseAppLauncher.start(Object) line: 79
EclipseStarter.run(Object) line: 368
EclipseStarter.run(String[], Runnable) line: 179
NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]
NativeMethodAccessorImpl.invoke(Object, Object[]) line: not available
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: not available
Method.invoke(Object, Object...) line: not available
Main.invokeFramework(String[], URL[]) line: 559
Main.basicRun(String[]) line: 514
Main.run(String[]) line: 1311
Main.main(String[]) line: 1287
I have no idea what to make of this. I am sure that if I understood this stack I would be able to fix it.
Can anyone see what the problem is? is there some problem with launching jars from within an eclipse action?
Maybe the Jar is built with a jdk newer than the the current used by eclipse. I had a similar problem in the past.
An exception is being thrown and eaten by the event handler. This exception is probably in the error log, so looking at that will probably give you some more hints.
The problem could be several things, but it is likely that the Connection class cannot be loaded for some reason and a ClassNotFoundException is being thrown.
精彩评论