Results 1 to 8 of 8
- 09-30-2011, 09:01 AM #1
Member
- Join Date
- Sep 2011
- Posts
- 12
- Rep Power
- 0
run a .class file at run time from another java file
Hello All,
I want to run a .class file at run time from another java file ,,, plz help me how can i code for this,,,,
moreover if that .class file doesnt contain "main", is it feasible to run using "main" of this caller java file....
Thanks in advance!
Ketan
- 09-30-2011, 01:31 PM #2
Member
- Join Date
- May 2011
- Posts
- 27
- Rep Power
- 0
Re: run a .class file at run time from another java file
Runtime.getRuntime().exec(cmd c:\java file.java);
but it should contain the main method then only it will run
- 09-30-2011, 02:20 PM #3
Re: run a .class file at run time from another java file
Call the class's constructor if it has a public one:I want to run a .class file at run time from another java file
Otherwise you need to know the name of a static method in the class that you can call like the main class:Java Code:TheClassName = new TheClassName(????); // call the class's constructor
Java Code:TheClassName.main(new String[]{}); // call the class's main method
- 10-03-2011, 05:25 AM #4
Member
- Join Date
- Sep 2011
- Posts
- 12
- Rep Power
- 0
Re: run a .class file at run time from another java file
Hello Dinesh, Norm,
Thanks for replying. Actually I dont have source code(java file) of that file in my system , I have only class file that i need to run by writing code for it.... please suggest
- 10-03-2011, 07:54 AM #5
Member
- Join Date
- May 2011
- Posts
- 27
- Rep Power
- 0
Re: run a .class file at run time from another java file
Hello Ketan,
Create a java class with main then call that class in this main class it will work i think so,
For example Dog.class
Class Anaimal {
public static void main(String args[]){
Dog g = new Dog();
g // u can access the all the other than private access specifier
}
} or
By using the reflection you can access class
you can try with the reflection i think so
- 10-03-2011, 08:50 AM #6
Member
- Join Date
- Sep 2011
- Posts
- 12
- Rep Power
- 0
Re: run a .class file at run time from another java file
Thanks Dinesh! There is some issue in this ,,,,,,,
This code will look for Dog class at compile time, but Dog.class file wont be available before compilation,,,,
- 10-03-2011, 01:46 PM #7
Re: run a .class file at run time from another java file
Put the Dog class file on the classpath during compilation.
- 10-04-2011, 05:16 AM #8
Member
- Join Date
- Sep 2011
- Posts
- 12
- Rep Power
- 0
Similar Threads
-
File copying and time stamp extraction(java)
By yande in forum AWT / SwingReplies: 3Last Post: 05-31-2011, 06:39 PM -
Add a jar file to Java load path at run time
By marioneil in forum Advanced JavaReplies: 5Last Post: 09-22-2010, 07:58 AM -
need help.. java class file...
By Madz in forum New To JavaReplies: 3Last Post: 11-21-2009, 03:42 AM -
converting java class file to exe file
By satheeshtech in forum Advanced JavaReplies: 5Last Post: 07-18-2009, 11:47 PM -
.class file to .java file
By makpandian in forum New To JavaReplies: 1Last Post: 02-20-2009, 06:46 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks