我正在开发一种语言的开发工具。现在我正在做运行的部分。我的意思是运行代码。因为我有自己的编译器,它是一个jar文件。所以我使用java运行时类来执行jar文件并将我的文件作为参数传递。但我有xml和java文件。如果我把这些文件与我的源文件,程序显示错误。那个xml文件不在eclipse文件夹中。但是xml文件和java文件应该与源文件一起使用。经过搜索。我发现classpath设置是个问题。我该如何解决这个问题。我正在附上我的代码。
import java.io.BufferedInputStream;
import java.io.File;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.handlers.HandlerUtil;
public class debug extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
System.out.println("HELLO WORLD");
String workingDir = System.getProperty("user.dir");
ISelection selection = HandlerUtil.getCurrentSelection(event);
System.out.println(selection + ":" + workingDir);
String jar = "";
String dir = "/home/durga/runtime-EclipseApplication/myApplication/src";
// Listing the contents
String[] files = new File(dir).list();
String[] arg1;
String arg = "";// /home/durga/final/myjar.jar";
for (String file : files) {
arg += "/home/durga/runtime-EclipseApplication/myApplication/src/"
+ file + " ";
}
// arg1 = arg.split(",");
arg = arg.substring(0, arg.length() - 1);
System.out.println("java -jar /home/durga/final/myjar.jar" + arg);
String str = "/home/durga/final/Eventj.jar ";
Runtime r = Runtime.getRuntime();
try {
// for(int i=0;i<arg1.length;i++)
// {
// r.exec("cd /home/durga/Desktop");
Process p = r.exec("java -jar " + str + " " + arg + "");
// }
System.out.println("java -jar " + str + " \t " + arg + "");
/*
* Now you are getting error, so I taken ErrorStream and printed the
* contents..
*/
BufferedInputStream bf = new BufferedInputStream(p.getErrorStream());
synchronized (p) {
p.waitFor();
}
int b;
while ((b = bf.read()) > 0)
System.out.print((char) b);
} catch (Exception e) {
System.err.println(e);
}
return null;
}
错误是
java.io.FileNotFoundException: /home/freely/freely/eclipse/channels.xml (No such file or directory)