我实际上是在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.but它仍然给出错误:
could not find or load main class mainclasses.emaildownload
可能是什么原因?
答案 0 :(得分:0)
在这一行:
public static void mai(String[] args) {
是一个' n'丢失。
更改为
public static void main(String[] args) {
答案 1 :(得分:0)
我相信命令应该如下:
java -cp <path-to-jar> <main-class>
提供:
命令应如下所示:
java -cp C:\Users\HP\Downloads\apache-tomcat-7.0.54-windows-x64\apache-tomcat-7.0.54\webapps\Mazil4.0\WEB-INF\classes\<jar-file> mainclasses.emaildownload
或者您可以使用通配符:
java -cp "C:\Users\HP\Downloads\apache-tomcat-7.0.54-windows-x64\apache-tomcat-7.0.54\webapps\Mazil4.0\WEB-INF\classes\*" mainclasses.emaildownload