我实际上正在尝试在Windows中使用另一个Java文件来运行我的Java文件....这是我的代码:
private static void printLines(String name, InputStream ins) throws Exception {
String line = null;
BufferedReader in = new BufferedReader(
new InputStreamReader(ins));
while ((line = in.readLine()) != null) {
System.out.println(name + " " + line);
}
}
private static void runProcess(String command) throws Exception {
String s=System.getProperty("user.dir");
s="C:\\Users\\HP\\Downloads\\apache-tomcat-7.0.54-windows-x64\\apache-tomcat-7.0.54\\webapps\\Mazil4.0\\WEB-INF\\classes";
File workingDir = new File(s);
System.out.println(q);
//new Foo().nonStaticMethod();
Process pro = Runtime.getRuntime().exec(command,null,workingDir);
printLines(command + " stdout:", pro.getInputStream());
printLines(command + " stderr:", pro.getErrorStream());
pro.waitFor();
System.out.println(command + " exitValue() " + pro.exitValue());
}
public static void mai(String[] args) {
String[] credentials=new String[4];int k=0;
for (String s: args) {
System.out.println(s);
credentials[k]=s;k++;
if(k==4)
break;
}
try {
//runProcess("javac test2.java");
//thread foo=new thread();
runProcess("java mainclasses.emaildownload "+credentials[0]+" "+credentials[1]+" "+credentials[2]+" "+credentials[3]+" ");
} catch (Exception e) {
e.printStackTrace();
}System.out.println("hI");
}
我通过使用workingDir给出了类的位置...并且我的文件路径是:
C:\Users\HP\Downloads\apache-tomcat-7.0.54-windows-x64\apache-tomcat-7.0.54\webapps\Mazil4.0\WEB-INF\classes\mainclasses\emaildownload.class
包名称是mainclasses。但是它仍然给出错误:
could not find or load main class mainclasses.emaildownload
可能是为什么?
最佳答案
在这一行:
public static void mai(String[] args) {
是“n”缺失。
改成
public static void main(String[] args) {
关于java - 使用另一个Java文件运行Java文件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24475830/