Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

compileClasses

  • 14-01-2005 6:32pm
    #1
    Closed Accounts Posts: 142 ✭✭


    hey havin a prob with this piece of code below it basically is a java program that compiles another java file in it using compileClasses it compiles but it doesn't work as hello.java is not compiled,any help you could give would be great


    import java.lang.Compiler;
    import java.io.*;

    public class TestCompile
    {
    public static void main(String[] args){


    File f = new File("Hello.java");
    System.out.println(f.isFile()); //test it is a file

    //name of java file to be compiled
    boolean b = Compiler.compileClasses("Hello.java");


    if(b)
    {
    System.out.println("it worked");
    }
    else
    {
    System.out.println("it didn't");
    }
    System.out.println(b);
    }
    }


    *****************
    public class Hello
    {
    public static void main(String[] args)
    {
    System.out.println("hello");
    }
    }


Comments

  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    Well, the first thought that comes to me is to put the compilation code in a seperate thread and have the calling thread wait until the compilation one is finished.


  • Closed Accounts Posts: 120 ✭✭test999


    "put the compilation code in a seperate thread and have the calling thread wait until the compilation one is finished."

    would that make it work? :rolleyes:
    just tell him what he's doing wrong, now,
    and you can show off, later.


  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    test999 wrote:
    "put the compilation code in a seperate thread and have the calling thread wait until the compilation one is finished."

    would that make it work? :rolleyes:
    just tell him what he's doing wrong, now,
    and you can show off, later.
    Show off? I have seen problems that are overcome by seperating processes. There are occasions where it is necessary to put heavy duty tasks to a new thread and make the original one wait, because the program jumps onto the next step pre-emptively. So yeah, it might help it work.

    Also, having read the documentation, I'm wondering if you are running this on an evoirnment that onlt has the JRE installed, as without the JDK, there is no installer to call. It might also be that the JDK isn't properly registered in the system, so that when the system is looking for the compiler, it can't find it and moves onto the next step.


  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    Why not just use ANT? Or is there a reason your doing it that way?


  • Closed Accounts Posts: 142 ✭✭lukeUCD


    The code is to test if student's submitted code for homework excercises compile or not.

    The problem seems to be that the System is not finding a compiler since System.getProperty("java.compiler") returns null.

    Is there a way to manually specify what compiler it should be using (as there are jdk's installed - it just doesn't seem to find them)?


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 27,370 ✭✭✭✭GreeBo


    lukeUCD wrote:
    The problem seems to be that the System is not finding a compiler since System.getProperty("java.compiler") returns null.
    ok, so how about system.setProperty(java.compiler, theJITCompiler)?
    do you have a JAVA_HOME environment variable?


  • Closed Accounts Posts: 1,502 ✭✭✭MrPinK


    There are occasions where it is necessary to put heavy duty tasks to a new thread and make the original one wait, because the program jumps onto the next step pre-emptively. So yeah, it might help it work.
    If the method call was non-blocking then that would mean that a seperate thread was being kicked off in the method already. But it would be very unusual for a method to be non-blocking when it's supposed to be returning a boolean indicating success or failure.


Advertisement