• 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

Running a java program from within another one

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!!
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you bundle everything into a ant script and run the ant script from java application.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
 
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic