Eclipse Plugin Action: Attach Eclipse debugger to a Remote Java Application programmatically
Sorry, this question is a duplicate of this post inside the Eclipse forum. As the Eclipse forum seems not to be very responsive, i'm trying my luck here. I already implemented this functionality with NetBeans, as described here, but now I need the same functionality for Eclipse.
In my development environment, a remote Java Server that i have to debug changes his IP address very often (I cannot change that fact). So i often have to change the IP-Address of that Server in my Eclipse Debug Configuration, where i have to update the address of the Remote Java Application.
I'm able to find out the IP address programmatically (it can be read from a property file), so i would also like Eclipse to use that "dynamic" IP address, without having to type it manually into the GUI everytime the address changes.
The first question is: Do i even need to write an Eclipse plugin to model this use case? Or can i use a command line parameter, which controls a running Eclipse instance? What i would really like would be if i can trigger Eclipse from commandline, passing the IP 开发者_高级运维address to Eclipse which should than attach the Debugger, like the following "pseudo"-command:
eclipse --debugger.attach.remote;address=192.168.178.111:9009
This way i could trigger Eclipse to attach it's Debugger from an external program, with the IP as an argument (Which is what I already implemented with NetBeans).
Second question: If i have to write a plugin for this (which should just provide one simple button, which triggers the lookup of the IP in the property file and then requests Eclipse to attach it's Debugger to this IP), how can i start? Can you suggest me the Eclipse module that i should access to control the Eclipse Debugger and maybe some documentations/examples/tutorials how to use it? What would be EXTREMELY great would be a code snippet which shows how to attach the Eclipse Debugger inside an Eclipse Plugin.
Thanks in advance for every hint!
I already found this quite related post : But it just gives a small hint, wich classes i can use. But i would rather see an code example, so i still appreciate some help.
EDIT:
As I already plan to write a bigger Eclipse-Plugin-Suite with several functionalities for my daily work (and I want to learn developing Eclipse plugins in general), I don't want to workaround this problem through e.g. the hosts file (although it's a really nice and simple approach). As I asked, I want to attach the Debugger from within an Eclipse Plugin.
You can assign the IP address a name using the hosts file.
That way, you can always use the same launch config.
Another option is to use a variable in your launch. Open the launch config dialog, click the button "Variables..." below "VM Arguments" and select "string_prompt".
Eclipse will remember the last value for you.
Last option: You could set up a DNS server for your network and make it resolve the IP address for everyone.
I came up with the same question today. To programmatically attach Eclipse's debugger you programmatically create a launch configuration that is then launched. The workspace needs to contain a project that contains the source code of the application to be debugged.
ILaunchConfigurationWorkingCopy remoteDebugLaunchConfig = createRemoteDebugLaunchConfiguration("ProjectNameThatHasTheSourceCode", "8000");
DebugUITools.launch(remoteDebugLaunchConfig, ILaunchManager.DEBUG_MODE);
The method createRemoteDebugConfiguration
creates the remote debug launch configuration:
private ILaunchConfigurationWorkingCopy createRemoteDebugLaunchConfiguration(final String projectName, final String port) throws CoreException {
ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
ILaunchConfigurationType type = manager
.getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_REMOTE_JAVA_APPLICATION);
final ILaunchConfigurationWorkingCopy remoteDebugConfig = type.newInstance(null, "remote debug");
// Set project
remoteDebugConfig.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, projectName);
// Set JVM debugger connection parameters
Map<String, String> connectionParameters = new HashMap<String, String>();
connectionParameters.put("hostname", "localhost");
connectionParameters.put("port", port);
remoteDebugConfig.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CONNECT_MAP, connectionParameters);
remoteDebugConfig.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_CONNECTOR,
"org.eclipse.jdt.launching.socketAttachConnector");
return remoteDebugConfig;
}
精彩评论