Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

executing java program from java

 
pvsr rao
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • 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
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
Norm Radder
Ranch Hand
Posts: 728
4
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
it is giving the error as cannot resolve symbol Hastable1.can we import that Hastableclass
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic