• 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

executing java program from java

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i want to execute ine java program from java.
iam sending my code.please see this. is it correct.when i executing it is not displaying any
public class prs
{
public static void main(String args[])
{
try
{

Runtime r=Runtime.getRuntime();
Process p=null;
p=r.exec("java Hastable1");//here Hastable1 is another java program
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
if this is not correct please tell me how to do this
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why not include Hastable1 in your classpath and call it from your program like this:

String[] parameters = ...;
Hastable1.main(parameters);

Or do you need access to InputStream and OutputStream?

Of course, if you have the source code, you can simply give it a proper API.
[ October 21, 2005: Message edited by: Ulf Dittmer ]
 
pvsr rao
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I Haven't understand these parameters and i don't need any parametersand my requirement is to execute some other java class from java program.please see where the problem is.if possible please modify my program and sent it to me as it is urgent for me
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ulf was saying that there is nothing special about a 'ajav program', it is a Java class that gets run using its 'main' method. You can call the 'main' method from your class and it will cause the other 'class' to be run just like it is run from the command line (more or less).

If you have other requirements please be more specific on the problem you are having.
 
pvsr rao
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i don't need any streams and i have used parameters also.but it is giving errors. from java program i need to execute some other java class
please send any code regarding this to me
 
pvsr rao
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my actual requirement is from the java program i have to start the weblogic server by interactively giving the domainname,servername etc.

i have executed like normal java class only.it is not giving any errors or output.just blankscreen is comming
 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What happens if you execute a program that has this statement:

Hastable1.main(new String[]{}); // call main() method of Hastable1

Copy and paste here the commandline and all of the console messages.
 
pvsr rao
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it is giving the error as cannot resolve symbol Hastable1.can we import that Hastableclass
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suggested earlier to include Hastable1 in your classpath. Without that, it will not work. And yes, you will need to add an import statement, but without the class being in the classpath that won't do much good.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic