Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Running a java program from within another one

 
geetha r
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi..

Could somebody please tell me how to run a java program from another one when they are in separate packages? The issue is that the java package from which I am trying to access it is not the same as the class file I need to access.

This is the code I am using now :

try{
Runtime runtime = Runtime.getRuntime();
File destDir = new File("/Users/abc/minion/trunk/translator/bin");

String[] args1 =
new String[]{"sh","-c",
"java EssencePrimeTranslator",
"/Users/abc/trans/problems/sokoban/modeltest.cm",
"/Users/abc/trans/problems/sokoban/modeltest.param",
"/Users/abc/trans/problems/sokoban/modeltest.minion"};

runtime.exec(args1,null,destDir);
}
catch(Exception exp){
System.out.println("Exception in run : " + exp.toString());
}

Thanks in advance for the help!!!
 
sathish kumar
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you bundle everything into a ant script and run the ant script from java application.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not an advanced question. Moving...

(And "chemical agent" please check your private messages)
 
geetha r
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Satish,

Thanks for your response. I am not sure of how to go about doing it though, could you please elaborate?
 
geetha r
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help with this...
The problem is solved. It can be done using the following :

Runtime runtime = Runtime.getRuntime();
String[] args1 = new String[]{
"java","-classpath",
"/Users/abc/minion/trunk/translator/bin","EssencePrimeTranslator",
"/Users/abc/trans/problems/sokoban/modeltest.cm",
"/Users/abc/trans/problems/sokoban/modeltest.param",
"/Users/abc/trans/problems/sokoban/modeltest.minion"};

runtime.exec(args1);
 
Scott Selikoff
author
Saloon Keeper
Posts: 4020
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"geetha r"

Your name still does not conform to the JavaRanch Naming Policy. Please review the policy and update it appropriately. This is your second warning.

Scott Selikoff
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic