How can I compile and run other java classes from within an application?

Hello there everyone! I really hope that someone can help me. I am writing a program that must be able to compile and run other java classes that are in different files, much like development environments like Kawa or Forte allow you to do.
There has to be a way of doing this ( I hope!! ), but i can't seem to find it!!
I have tried using this command to compile:
Runtime.getRuntime().exec ("c:\\programs\\javac className.java");
...and this one to run:
Runtime.getRuntime().exec ("c:\\programs\\java className");
...but neither works!!! I can compile and run classes that are in the same file as my application, but I can't get it to work at all for files in different directories or files.
PLEASE, PLEASE, PLEASE help me - i've run out of ideas, and i need this to be working in 3 days!!!
Thank you very much for any help anyone can give me, I really appreciate it!! Thanks again!!
Adrian ( ...in distress!! )

public class JavaCompiler{
   public static void main(String[] args)throws Exception{ //sorry bout the laziness
      if(args == null || args.length != 1){
         System.out.println("Usage: java JavaCompiler MyClass.java");
         System.exit(0);
      String className = args[0];
      Runtime rt = Runtime.getRuntime();
      Process p = rt.exec("javac " + className); //consider setting cpath for this
      p.waitFor();
      //now try to run after it is done.
      p = rt.exec("java " + className.substring(0, (className.length() - ".java".length()));
      p.waitFor();
      //do some other stuff
}This should get you going. You may consider looking into the System.getProperty() method in order to determine the type of OS it is running on in order to findo out what command to run. I know that the sun tool listed above is nice, but by my understanding the sun tools provided are not guaranteed to stay the same. I'm no expert on this matter, but that is one of the reasons there is no API documentation for those tools. Also, I don't believe those tools come packaged with the JRE. (Of course if you are making an IDE it will be expected that the user has an sdk installed. Good luck with figuring this thing out.

Similar Messages

  • How to compile and run a .java file from another java program

    hello,
    can any one tell me how to compile and run a *.java* file from another java program which is not in same directory?

    Well a smarter way of implementing this is by using a solution provided by Java Itself.
    If you are using J2SE 6.0+ there is an in built solution provided along with JDK itself and inorder to go ahead with solution the below are set of API which you;d be using it for compiling Java Programs (Files)
    http://java.sun.com/javase/6/docs/api/javax/tools/package-summary.html
    How do i do that ??
    Check out the below articles which would help you of how to do that
    http://www.ibm.com/developerworks/java/library/j-jcomp/index.html
    http://www.javabeat.net/javabeat/java6/articles/java_6_0_compiler_api_1.php
    http://books.google.com/books?id=WVbpv8SQpkEC&pg=PA155&lpg=PA155&dq=%22javax+tools%22+compiling+java+file&source=web&ots=XOt0siYe-f&sig=HH27ovuwvJgklIf8omTykUmy-eM
    Now once we are done with compilation.In order to run a Specific class all you ought to do is create an object and its specific methods of a specified class included in the CLASSPATH which you can manage it easily by usage little bit reflections.
    Hope that might help :)
    REGARDS,
    RaHuL

  • How can I install and run the Java Telephony API

    Hello!
    I have downloaded the Java Telephony API but I couldn't find the installation notes for installing it on my PC (Win2000).
    Can anyone help me?

    Since the package is downloaded as just .class files just set your classpath like you normally would if you were creating your own package...I personally would install the class file version...run a sample program and see if this works...

  • How can i compile and run javatv ri on linux platform

    hi,
    can any one plz help me what is the requirement to execute javatv reference implementation on linux and what are the steps i should followand, and any commands required
    thx in adv

    See this question :-)
    http://forum.java.sun.com/thread.jsp?forum=54&thread=289574

  • How to compile and run a java program?

    I am getting this error message, what to do?
    Exception in thread "main" java.lang.NoClassDefFoundError:
    Thanks for you help.
    Ajay

    Hello,
    I believe that this error is caused because when you
    compile and run a java program, you have to use the
    same name that is next to public class. For example,
    the program name is next to the word public class.
    For example, if a program began like this:
    public class Concat
    then the name of the program in this case is Concat
    and when you compile it you type: javac Concat.java
    when you run it type: java Concat
    depending on the name of your program.and depending on whether the class is in a package. And depending on what directory you are currently in.
    Also depending on if you set your class path you might
    have to type the above like this: jdk1.2.1\bin\javac
    Concat.java to compile, and to run you would have to
    type jdk1.2.1\bin\java Concat where you would replace
    Concat with the name of your program and replace
    jdk1.2.1 with the name of your version of java, that
    is again if you do not have your classpath set. Hope
    this helps.Your examples have nothing to do with whether the CLASSPATH is set--only with whether the PATH is set. And, it may not be jdkXXX\bin. The path to the JDK (in this case, to javac and java executables) could be anything. Classpath should be set on the command line. The OP probably did NOT set a classpath on the command line (preferred), or in the environment variables.
    Also, make sure you did not forget to put:
    public static void main(String[ ] args)
    on the line underneath the line where it says "public
    class Concat" where Concat is the name of your
    program. Again, I hope this helps.Irrelevant (with the info we have from the OP so far). The error says that the JVM can't even find the class--not that the class doesn't have a main. The "main" referred to in the error message is within the JVM itself.
    OP: Did you fix your problem? If not, what directory are your files in? Are they in a package? What command are you typing to get that error? That is, please tell us your entire command line.

  • How can I install and run a Windows program on my MacBook Pro/?

    How can I install and run a Windows program on my MacBook Pro?

    You have several options.
    1, Use a Virtual Machine like Vmware, Parallels etc... to Create a Virtual Windows Installation and Run your program in there.  A Virtual MAchine will runn in a Window on your Desktop and share your Mac's resources RAM HD space processor. Your MAc desktop will still be available while you run Windows install.
    http://www.parallels.com/
    2. Install Windows on a partition using Bootcamp. It will run a full installation of Windows you can boot into, and run your programs.  The Mac desktop will not available until your reboot the computer and start in OSx instead of Windows.
    https://www.apple.com/support/bootcamp/
    3. Use Wine /  Winebottler to run the Application without the need for a complete Windows installation.
    http://winebottler.kronenberg.org/

  • How can I install and run lookout 6.1 on windows server 2008 64-bit without errors?

    How can I install and run lookout 6.1 on windows server 2008 64-bit without any errors?
    I was unable to start the lookout applcation after I install the lookout 6.1 on windows server 2008 64-bit.
    (error code: 0xC0000142). Please help!
    Thanks

    This will pobably do http://joule.ni.com/nidu/cds/view/p/id/1051/lang/en but the major issue is that you should concentrate and read the instructions carefully. My two cents.
    Dieet
    Afvallen

  • How can I boot and run my Mac Mini on my 12" PwrBk display using firewire?

    How can I boot and run my Mac Mini on my 12" PwrBk display using firewire?

    bwhit:
    Welcome to Apple Discussions.
    No reason why you should not be able to do it using Firewire Target Disk Mode. Here's what you do:
    1. With both computers shut down connect both via firewire.
    2. Startup the Mini and hold down "T" key immediately after chime.
    3. Startup the PB and immediately after chime hold down Option key.
    4. Select second HDD icon on the screen and click on the right pointing arrow.
    5. Computer will boot from Mini's HDD.
    Be sure to shut down PB completely before shutting down Mini.
    Please do post back with an update or with further questions or comments.
    Cheers
    cornelius

  • How can i display the result of java class in InputText ?

    Hi all,
    How can i get the result of java class to InputText Or OutputText ???
    also can every one in the forum give me road map for dealing with java in oracle adf because i'm beginner in oracle adf
    i saw some samples in oracle adf corner but it's difficult for me.

    User,
    Always mention your JDev version, technologies used and clear usecase description (read through this announcement : https://forums.oracle.com/forums/ann.jspa?annID=56)
    How can i get the result of java class to InputText Or OutputText ???Can you elaborate on your requirement? Do you mean the return value of a method in a class as output text? Or an attribute in your class (bean?) as text field?
    -Arun

  • How can I login and retrieve my user file from the trash?

    I was trying to find out where all my HD had gone, which a did using ‘What Size’.
    I found what looked like an old backup file so I put the file in the trash.
    It turns out that the file was my user file. So now I can’t login to as the user.
    How can I login and retrieve my user file from the trash?

    The Digital Editions forum is here, in case this is what you are talking about:
    http://forums.adobe.com/community/adobe_digital_editions
    If you are not, I apologize for the misunderstanding.

  • How can i Flash and restore the firmware ( EFI ) from a Macbook pro ( late 2008 , 5.1 ) ??

    How can i Flash and restore the firmware ( EFI ) from a Macbook pro ( late 2008 , 5.1 ) ??
    Please help me !!

    The Seagate backup drive I bought doesn't support 10.5.8
    The only reason I can see for that is it's formatted NTFS, which would likely be Read Only in 10.5.x, if you can reformat it MacOS extended, which would erase everything on it now, then that should work for your purposes.

  • How can I copy and paste the art work from album covers?

    How can I copy and paste the art work from album covers?

    I don't think the list style transfers. Copy and paste the text in to Mail, select it and then choose "Insert Numbered List" as a work around.

  • HT3702 How can I stop and remove my credit card from my iPad ,my children keep buying games and I want to stop it......please help me to remove any payment from now on.

    How can I stop and remove my credit card from my iPad ,my children keep buying games and I want to stop it......please help me to remove any payment from now on.

    iOS: Understanding Restrictions
              http://support.apple.com/kb/HT4213

  • How can I open and fill out a Secured Adobe PDF job application?

    How can I open and fill out a Secured Adobe PDF job application?

    Hi margueritew68053277,
    You should be able to fill that out using the free Adobe Reader, or Adobe Fill & Sign.
    Best,
    Sara

  • How can I locate EBS FND security java classes being referenced from packages?

    Hi All,
    I need to load few java classes in database whose methods are being called from SQL packages. For example, package FND_WEB_SEC calls methods from java class "oracle.apps.fnd.security.WebSessionManagerProc"
    Which means I need to load this class on my db for it to be used correctly.
    I am unable to locate this and few other java classes.
    Can anyone suggest where can I find these?
    Thanks,
    Ishwar

    Hi Ishwar,
    Please have a look at the forum search, as it would be of assistance..
    Forum Search: Where are Java classess
    Best Regards,

Maybe you are looking for

  • Our accountant is no longer allowed access to the QuickBooks file

    My main server is Small Business Server 2008 Standard (i.e. pre-R2).  I have another box running Server 2012 that's just acting as a Hyper-V host.  On that server I have three relevant VMs, all Windows 7 Professional and joined to the domain. One is

  • Opening Balances changes when running business rules

    Good morning, We are experiencing problems with the opening balance calculation (Flow: F100) when running the consolidation business rules in BPC 10.1. For example, in 2013.12, Entity 1111 and Account C_ENL_DIV, the ending balance (Flow: F900) is 180

  • Export part of the project

    Anybody found a way to only export a section of a project? IN FCP 7 I would just go in the timeline and press I and O to select the wanted area and that's it. It's a very useful feature if I need to export a clip to do some stuff in AE and then bring

  • Re: Bluetooth Related Issues with Car kits regarding the Palm Pre Post 1.2.1

    Make/Model:  Nissan Maxima Year:  2007 Carkit Model info (Manufacturer, firmware version, etc):  OEM with Nav Details of problem: (e.g. pairing drops, static on the line, buttons mapped incorrectly, etc)  Since updating to webOS 1.3.5, the connect an

  • Firefox crashes when I try to launch it

    Firefox was working Ok until 06/11/11 but when I tried to launch the application it constantly crashes.