日期:2014-05-18  浏览次数:20744 次

jsp中调用java编译器的问题
Java code

        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
        int results = compiler.run(null, null, null, "C:\\Program Files\\Apache Software   Foundation\\Tomcat 6.0\\webapps\\test\\JavaProgramming.java");
        out.println((results == 0)?"编译成功":"编译失败");
        Runtime run = Runtime.getRuntime();        
        Process p = run.exec("java JavaProgramming");        
        BufferedInputStream in = new BufferedInputStream(p.getInputStream());
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        String s = br.readLine();
        while (s.equals("hello"))
        out.println("the program is correct");



classpath中已经添加了路径了 

这是在一个jsp文件中调用编译器的, 想运行JavaProgramming并得到运行结果,编译没有问题,但run.exec()时出现错误,总是类找不到的错误,classnofound.

------解决方案--------------------
编译之后的class文件放到哪去了?
同样用绝对路径试试看呢。
------解决方案--------------------
确实是的,再cmd下用绝对名貌似不行,需要用cd切换到当前目录下