using perl script to compile java

D

David

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
 
T

Tad McClellan

David said:
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
 
T

thumb_42

David said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top