File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 6
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: 6
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: 6
Thanks for the quick reply , let me try
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36453
    
  15
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
Beginner at Ant and Servlets
check values in a csv file in all files in a directory
static final variable initialization inside instance init block
Directory / File not found
Getting Error Help........