• Post Reply Bookmark Topic Watch Topic
  • New Topic

RunTimeUsage  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,
I want to run a java class from another class.
I tried like this..
Runtime.getRuntime("java C:\test2");But test2 did not run.
But I could execute this command sucessfully.
Runtime.getRuntime("javac C\test2.java");
I could see class file generated for this.

Please suggest me how to run a java class .....

Thanks in advance.
 
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Runtime class is part of core java. This forum is reserved for APIs that does not fit into other categories. Hence, transferring this topic to Java in General.... ahhh... hmmmm.... Intermediate.

Henry
 
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Runtime.getRuntime("java C:\test2");But test2 did not run.

What happens if you open a command prompt window and type "java C:\test2"? It will not run, because this is an invalid command. You pass a class name to the "java" command, not a filename. "C:\test2" is not a valid class name. Try running this command:

java -cp C:\ test2

(note the space between C:\ and test2).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!