Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
sravan ku
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 157
1
Android Java MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sravan, please put your java code in code tag.
 
sravan ku
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi harshvardhan ,

Unable to add the code tag to my java code .
 
harshvardhan ojha
Ranch Hand
Posts: 157
1
Android Java MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use StandardJavaFileManager to get Your Java Object.
You can find example here compiler.
 
sravan ku
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the quick reply , let me try
 
Campbell Ritchie
Sheriff
Posts: 48645
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic