Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Debugging an eclipse application running programmatically
Debugging an eclipse application running programmatically [message #1832649] Tue, 22 September 2020 16:48 Go to next message
Miroslav Shipilov is currently offline Miroslav ShipilovFriend
Messages: 2
Registered: September 2020
Junior Member
Hello!

I have simple example of my app:
package plugin;

import org.eclipse.equinox.app.IApplication;
import org.eclipse.equinox.app.IApplicationContext;


public class MyActivator implements IApplication  {
	@Override
	public Object start(IApplicationContext context) throws Exception {
		for (int i=0 ; i < 10 ; i++) {
			Thread.sleep(10000);
			System.out.println("MyActivator " + i);	
		}
		return null;
	}
	@Override
	public void stop() {
	}
}


In my test I create a startup configuration for this app and launch it, then do all sorts of checks

Example test:
package test;

import java.io.IOException;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.core.IStreamListener;
import org.eclipse.debug.core.model.IStreamMonitor;
import org.junit.Test;

public class MyTest { 
	boolean isStart;
	
	@Test
	public void test1() throws CoreException, InterruptedException, IOException {
			
			
			ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
			   ILaunchConfigurationType type =
			      manager.getLaunchConfigurationType("org.eclipse.pde.ui.RuntimeWorkbench");
			
			 
			ILaunchConfigurationWorkingCopy workingCopy =
			      type.newInstance(null, "Start java");
			
			workingCopy.setAttribute("application","Plugin.MyActovator1");
			workingCopy.setAttribute("org.eclipse.jdt.launching.PROGRAM_ARGUMENTS","-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:52245");
			workingCopy.setAttribute("org.eclipse.jdt.launching.JRE_CONTAINER","org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8");
			workingCopy.setAttribute("product","org.eclipse.platform.ide");

			ILaunchConfiguration configuration = workingCopy.doSave();
						
			ILaunch laucnh = configuration.launch(ILaunchManager.DEBUG_MODE, null);

			laucnh.getProcesses()[0].getStreamsProxy().getOutputStreamMonitor().addListener(new IStreamListener() {
				
				@Override
				public void streamAppended(String text, IStreamMonitor monitor) {
					System.out.println("APP INFO " + text);
					
				}
			});
					
			for (int start = 0; start < 10; start++) {
				if (isStart) {
					break;
				}
				Thread.sleep(5000);
			}
	}
}


The main question is how can I debug the application when running the test since it runs in a separate process? "Remote java application" doesn't help.
Re: Debugging an eclipse application running programmatically [message #1833540 is a reply to message #1832649] Fri, 16 October 2020 09:51 Go to previous message
Miroslav Shipilov is currently offline Miroslav ShipilovFriend
Messages: 2
Registered: September 2020
Junior Member
I found a solution. In the startup configuration, add the VM arguments "-vmargs -Xdebug -Xrunjdwp:transport=dt_socket,server=n,suspend=y,address=" + port;". and set ILaunchManager.RUN_MODE. Using Launch group to launch Remote server in Listener mode and the test.
Previous Topic:MyEclipse Related Java Projects
Next Topic:Selected string not delete while type new string.
Goto Forum:
  


Current Time: Sat Oct 24 18:41:52 GMT 2020

Powered by FUDForum. Page generated in 0.01777 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top