aspose file tools*
The moose likes Java in General and the fly likes executing java program from java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "executing java program from java" Watch "executing java program from java" New topic
Author

executing java program from java

pvsr rao
Ranch Hand

Joined: Oct 05, 2005
Posts: 102
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
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
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 ]

Ping & DNS - my free Android networking tools app
pvsr rao
Ranch Hand

Joined: Oct 05, 2005
Posts: 102
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
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

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

Joined: Oct 05, 2005
Posts: 102
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

Joined: Oct 05, 2005
Posts: 102
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
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 687
    
    1
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

Joined: Oct 05, 2005
Posts: 102
it is giving the error as cannot resolve symbol Hastable1.can we import that Hastableclass
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
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.
 
jQuery in Action, 2nd edition
 
subject: executing java program from java