• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 157
1
Android MySQL Database Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 MySQL Database Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the quick reply , let me try
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic