My program is trying to compile all the .java file under a defined directory.
This code works well on Window 7 but when same code is get executed on Liunx, it show an error "cannot read : *.java".
I have already tried a lot of option, but nothing working on linux machine.. I am literally piced-off .. Can someone help me out , what is going wrong here.
Here is code.
Any help will be appreciated..
Lanny Gilbert
Ranch Hand
Joined: Jun 11, 2002
Posts: 103
posted
0
A couple of things come to mind.
1.) Your program has the classpath and directory set to "."
Is it possible that the directory passed into your program is the same as "." on Windows, but not on Linux? By thing, I mean are you running your program
in the same directory as the java files you want to compile on Windows, but not on Linux?
2.) Does the directory name passed into your program contain spaces?
Note the way I have made the 'javac' command all one argument. On *nix that matters, on windows it does not matter as much but there are other problems.
P.S. You should read that article because you have also failed to handle the Process 'stdout' which could cause a deadlock. Since you don't really care about either 'stdout' or 'stder'' you would do better to use ProcessBuilder then you can merge 'stdout' and 'stderr' and just print out one stream.
Retired horse trader.
Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Also look at the JavaCompiler class. It allows you to invoke the compiler without Runtime.exec()
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Lanny Gilbert wrote:A couple of things come to mind.
1.) Your program has the classpath and directory set to "."
Is it possible that the directory passed into your program is the same as "." on Windows, but not on Linux? By thing, I mean are you running your program
in the same directory as the java files you want to compile on Windows, but not on Linux?
2.) Does the directory name passed into your program contain spaces?
1. By Runtime class, i am trying to invoke the JAVAC command under source code directory .. And it is same on window ans well as linux. (As least Runtime.exec() documentation says that).
2 . Directory name doesn't contain any space.
Note the way I have made the 'javac' command all one argument. On *nix that matters, on windows it does not matter as much but there are other problems.
P.S. You should read that article because you have also failed to handle the Process 'stdout' which could cause a deadlock. Since you don't really care about either 'stdout' or 'stder'' you would do better to use ProcessBuilder then you can merge 'stdout' and 'stderr' and just print out one stream.
I even tried to give the full path of java source class, but it was giving me same problem..
Still i would like to try your option..
Note the way I have made the 'javac' command all one argument. On *nix that matters, on windows it does not matter as much but there are other problems.
P.S. You should read that article because you have also failed to handle the Process 'stdout' which could cause a deadlock. Since you don't really care about either 'stdout' or 'stder'' you would do better to use ProcessBuilder then you can merge 'stdout' and 'stderr' and just print out one stream.
Note the way I have made the 'javac' command all one argument. On *nix that matters, on windows it does not matter as much but there are other problems.
P.S. You should read that article because you have also failed to handle the Process 'stdout' which could cause a deadlock. Since you don't really care about either 'stdout' or 'stder'' you would do better to use ProcessBuilder then you can merge 'stdout' and 'stderr' and just print out one stream.
i just tried this.. and it doesn't worked out ..
Works for me - I tested it before I posted it. I initially tested using Runtime.exec() and then later using ProcessBuilder and both worked flawlessly. What are the symptoms of "it doesn't worked out" ? What does your code now look like? What is the directory structure of '.' ? Are you sure you are specifying the correct working directory? Even though it should make no difference, are you processing 'stdout'.
Ernest Friedman-Hill
author and iconoclast
Marshal
James Sabre's solution is the right one. If you tried it, and it didn't work, you are doing it wrong. Note that there are only three arguments: "sh", "-c", and "javac -d . -cp . *.java". It won't work if you break the command line into multiple arguments.
Note the way I have made the 'javac' command all one argument. On *nix that matters, on windows it does not matter as much but there are other problems.
P.S. You should read that article because you have also failed to handle the Process 'stdout' which could cause a deadlock. Since you don't really care about either 'stdout' or 'stder'' you would do better to use ProcessBuilder then you can merge 'stdout' and 'stderr' and just print out one stream.
i just tried this.. and it doesn't worked out ..
Works for me - I tested it before I posted it. I initially tested using Runtime.exec() and then later using ProcessBuilder and both worked flawlessly. What are the symptoms of "it doesn't worked out" ? What does your code now look like? What is the directory structure of '.' ? Are you sure you are specifying the correct working directory? Even though it should make no difference, are you processing 'stdout'.
I have change the command as you suggest, but facing the different problem - "Unable to launch Java complier. Please check you have install JDK". Please check the first post where i have put the whole method definition..
Thanks for helping out.
Parmendra Tyagi
Greenhorn
Joined: Feb 12, 2010
Posts: 6
posted
1
Great Thanks to James Sabre and Ernest Friedman-Hill .. I was making a silly mistake. I was using
While the correct one is -
Abstract Meta
Greenhorn
Joined: Apr 12, 2012
Posts: 1
posted
0
How about using some compilation utility, here is one option