using perl script to compile java

Discussion in 'Perl Misc' started by David, Feb 29, 2004.

  1. David

    David Guest

    Hi everybody,
    I'm trying to do a small perl sript to compile a basic java code.
    This is what I've done so far. the name of Java code is "hello.java",
    and the name of the perl script is "compile". This is how I run it
    :compile Hello.java
    There are 2 steps, the first one is to create the hello.class which is
    normally done, by writing javac hello.java.
    the script is :
    'javac $argv[0]';

    The second step is to do java hello, using the Hello.class created,
    and this what I did in my script to do that :
    opendir (DH, "."); # open the local directory
    foreach $file (@list) {
    if ($file =~ /class$/) {
    $trouve = $file;
    last;} # search the Hello. class.
    }
    @test = split(/.class/,$trouve,2); # separate Hello from Hello.class
    and run it
    'java $test[0]'; #this line of code is supposed to do the step 2 but
    it doesn't work.

    any idea is welcomed.

    Cheers;

    David
     
    David, Feb 29, 2004
    #1
    1. Advertising

  2. David <> wrote:

    > I'm trying to do a small perl sript to compile a basic java code.



    You want to do more than just compile java code.


    > There are 2 steps, the first one is to create the hello.class which is
    > normally done, by writing javac hello.java.



    The 1st step is compiling.

    !system 'javac hello.java' or die 'problem compiling';


    > The second step is to do java hello



    The 2nd step is _executing_ what was compiled in step 1.

    !system 'java hello' or die 'problem executing';



    > opendir (DH, "."); # open the local directory



    Why is this here?

    You never make use of the DH directory handle in your code...

    What if you are not able to open the directory? You should check to
    see if you got what you asked for:

    opendir(DH, ".") or die "could not open cwd $!";


    > foreach $file (@list) {



    You have never put anything into @list, so the code in the
    foreach block in never executed, so we can skip over that
    without even reading it.



    > any idea is welcomed.



    1) see the Posting Guidelines that are posted here frequently

    2) perldoc -f system


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Feb 29, 2004
    #2
    1. Advertising

  3. David

    Guest

    David <> wrote:
    > Hi everybody,
    > I'm trying to do a small perl sript to compile a basic java code.
    > This is what I've done so far. the name of Java code is "hello.java",
    > and the name of the perl script is "compile". This is how I run it


    Have you considered 'ant' for this task. (it'd probably be easier)

    Jamie
     
    , Feb 29, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wet Basement
    Replies:
    1
    Views:
    2,556
    BobMonk
    Jul 15, 2003
  2. dpackwood
    Replies:
    3
    Views:
    1,839
  3. Nagaraj
    Replies:
    1
    Views:
    901
    Lionel B
    Mar 1, 2007
  4. timjowers
    Replies:
    7
    Views:
    4,398
    heyjude
    Feb 2, 2011
  5. vikrant
    Replies:
    4
    Views:
    290
Loading...

Share This Page