Configuring and running a java file inside the plugin
Answered
Hello,
I'm trying to create an Intellij's IDEA out of an eclipse's one.
There are many classes in eclipse that don't exist in intellij IDEA.
I need to build, compile and run a given java file..
This is the code in Eclipse:
public class Launcher extends AbstractJavaLaunchConfigurationDelegate {
public static final String LAUNCH_CONFIGURATION_TYPE_ID = "agt0.dev.launch.launcher";
public static final String PROBLEM_ATTRIBUTE = "PROBLEM";
public void launch(final ILaunchConfiguration configuration, final String mode,
ILaunch launch, ProgressIndicator monitor) throws CoreException {
if (!SharedDataUnit.UNIT.isLibreryExists()){ // checks if lib is in AZ WORKSPACE
FrameworkUpdateUnit.UNIT.testForFirstUpdate();
launch.terminate();
return;
}
IJavaProject project = getJavaProject(configuration); // creates a java project with specific config
if (project == null){
project = EclipseUtils.getActiveJavaProject();
}
AgentZeroProject azp = new AgentZeroProject(project); // creates a AZProject
if (project == null) {
System.out.println("The Launcher was called with no project!!!");
} else {
IVMInstall vm = verifyVMInstall(configuration);
IVMRunner runner = vm.getVMRunner(mode);
final String localPath = project.getProject().getLocation().toOSString();
String binClassPath = azp.getBinDirectory().getAbsolutePath();//project.getProject().getFolder("bin").toString();
File[] libFiles = SharedDataUnit.UNIT.getAllJarsInLib();
String[] classPath = new String[libFiles.length + 1];
for (int i=0; i<libFiles.length; i++){
classPath[i] = libFiles[i].getAbsolutePath();
}
classPath[libFiles.length-1] = binClassPath;
VMRunnerConfiguration runConfig = new VMRunnerConfiguration(
"bgu.dcr.az.dev.Agent0Tester", classPath);
println("localpath is " + localPath);
LinkedList<String> programArgs = new LinkedList<String>(){{
add("-f"); add("test.xml");
add("--sfp"); add("fails");
add("--emode"); add(mode);
}};
runConfig.setProgramArguments(programArgs.toArray(new String[0]));
String vmAttributes = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, "-Xmx1024m -XX:MaxPermSize=128m -server");
runConfig.setVMArguments(vmAttributes.split("\\s+"));
runConfig.setWorkingDirectory(localPath);
// Bootpath
String[] bootpath = getBootpath(configuration);
runConfig.setBootClassPath(bootpath);
// this will attach the source to the execution.
setDefaultSourceLocator(launch, configuration);
runner.run(runConfig, launch, monitor);
System.out.println("launcer done");
}
}
Can you please tell me what are the classes that equivalent to the code above?
thank you very much
Please sign in to leave a comment.
There is zero overlap between Eclipse and IJ Platform. You can achieve this with builtin "Scratch Files" functionality already in IJ. https://stackoverflow.com/questions/33562958/how-to-run-java-scratch-file-in-intellij-idea
Can you explain please what does a java scratch file mean?
please see https://www.jetbrains.com/help/idea/run-debug-configuration-java-scratch.html