wood burning stoves 2.0*
The moose likes Java in General and the fly likes how to compile and run a program from another java program? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "how to compile and run a program from another java program? " Watch "how to compile and run a program from another java program? " New topic
Author

how to compile and run a program from another java program?

sravan ku
Greenhorn

Joined: Feb 15, 2013
Posts: 7
Hello Everyone ,

This is my code snippet

<code>
public void executeJavaFile() {
String ts = testCaseName + ".java";
System.out.println("testcasename" + testCaseName);

JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();

String fr = "D:\\QA\\src\\com\\QAAutomation\\";
String sf = fr+testSuiteName;
System.setProperty("user.dir",sf);
System.out.println(sf);

String f = ts;
String gs = System.getProperty("user.dir");
System.out.println("present dir" +gs);
int result = compiler.run(null, null, null,f );
System.out.println("Compile result code = " + result);
</code>



out put :
javac: file not found: gooast.java
Usage: javac <options> <source files>
use -help for a list of possible options
Compile result code = 2


I am passing the .java file which is there in the user.dir location .But still I am unable to compile the the program . every time it is throwing file not found .


Can any one please have a look into my code and suggest me ,what required to be add into the existing code .




Thanks,
ksk
harshvardhan ojha
Ranch Hand

Joined: Jul 26, 2007
Posts: 157
    
    1

Hi Sravan, please put your java code in code tag.
sravan ku
Greenhorn

Joined: Feb 15, 2013
Posts: 7
Hi harshvardhan ,

Unable to add the code tag to my java code .
harshvardhan ojha
Ranch Hand

Joined: Jul 26, 2007
Posts: 157
    
    1

Use StandardJavaFileManager to get Your Java Object.
You can find example here compiler.
sravan ku
Greenhorn

Joined: Feb 15, 2013
Posts: 7
Thanks for the quick reply , let me try
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38057
    
  22
sravan ku wrote:Hi harshvardhan ,

Unable to add the code tag to my java code .
Yes, you can. They are not html tags but BB tags and they are added by the code button, not by hand. Please try again. Highlight the entire block of code and click the code button. Bear gave you a link on your other thread.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to compile and run a program from another java program?
 
Similar Threads
static final variable initialization inside instance init block
Directory / File not found
Getting Error Help........
check values in a csv file in all files in a directory
Beginner at Ant and Servlets