Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > J2EE
J2EE General J2EE (Java 2 Enterprise Edition) discussions. Questions not specific to EE will be redirected elsewhere.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the J2EE section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old July 28th, 2005, 09:03 AM
Registered User
Join Date: Jun 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default java.lang.Runtime

Hi all,

cud anyone help me with java.lang.Runtime. I am writing code to compile and execute another java class. The code is,
import java.util.*;
import java.io.*;

public class NewClass
    public static void main(String args[])

       Runtime rt = Runtime.getRuntime();
       Process proc = rt.exec("javac C:\\HelloWorld.java");
       StreamGobbler ig = new StreamGobbler(proc.getInputStream(), "output");
       int exitVal = proc.waitFor();
       System.out.println("ExitValue: " + exitVal);

       proc = rt.exec("java C:\\HelloWorld");
       ig = new StreamGobbler(proc.getInputStream(),"printed version");
       StreamGobbler igErr = new StreamGobbler(proc.getErrorStream(),"Error");
       exitVal = proc.waitFor();

       System.out.println("ExitValue at the end"+exitVal);
     }catch(Exception e){}


class StreamGobbler extends Thread
    InputStream is;
    String type;

    StreamGobbler(InputStream is, String type)
        this.is = is;
        this.type = type;

    public void run()
            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);
            String line=null;
            while ( (line = br.readLine()) != null)
                System.out.println(type + ">" + line);
            } catch (IOException ioe)


the class compiles fine, but when I execute it, following error comes

java.lang.NoClassDefFoundError: C:\HelloWorld
Exception in thread "main"

Could anyone help me with this. I wud appreciate your help.


Old August 2nd, 2005, 02:14 AM
Authorized User
Join Date: Aug 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to olupas

Try using reflection for executing

Regards LOOP

Similar Threads
Thread Thread Starter Forum Replies Last Post
Root Cause:java.lang.NoSuchMethodError: java.util. anees81 JSP Basics 3 March 1st, 2011 08:55 AM
java.lang.OutOfMemoryError: Java heap space meetkotresh J2EE 1 February 2nd, 2008 01:52 AM
java.lang.IllegalStateException: priyatowin J2EE 0 September 13th, 2006 10:57 PM
java.lang.StackOverFlowError mrafeeq Pro Java 0 August 10th, 2006 12:51 PM
java.lang.ArrayIndexOutOfBoundsException chiraagb Pro JSP 1 July 1st, 2006 07:21 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.