as above, isit possible? :o:o
Printable View
as above, isit possible? :o:o
You'll have to be more specific.. what do you mean by "placing packages of the same directory"?
src packages
hmm... so if I understand you correctly, you want to create an array of File references to all files in the current directory?
If this is the case, I'd recommend using the listFiles() method (you'll need to check if the file is indeed a file and not a directory, and if you want, recurse down the folder structure)
Code :File directory = new File("./someDirectory"); File[] allFiles = directory.listFiles();
the problem is, say i cant import all the packages in src.
example:
import src.*;
get what i mean?
if i can import them then putting them in an array wouldnt be a problem :\'(!!!
... so you want to dynamically link .class files with your program? In which case, a quick google search came back with this:
Java reflection
yeah man, thats something i wanna do like what i posted in my previous thread. trying to read on it. im a nub :o:o hehe
thanks helloworld
yeah, reflection is totally what i need. using strings to get classes and its methods. :D wooo :-":-":-":-":-"
Just out of interest, what are you actually trying to achieve?
running other classes in a class automatically
Code :final Class<?> clazz = Class.forName("my.class.package.and.name.Here"); final Object object = clazz.newInstance();
Now just cast it to whatever it is you know it will be or use more reflection on the object to run methods.
// Json
thanks was able to do it. here's my code
Code :ClassLoader classLoader = RunExistingBuildAndTestplan.class .getClassLoader(); try{ Class aClass = classLoader.loadClass("testscripts." + caseName + "." + caseName); System.out.println("aClass.getName() = " + aClass.getName()); Method mainMethod = aClass.getMethod("main", new Class[] { String[].class }); mainMethod.invoke(null, new Object[] { new String[] { "", "" } }); }
Grats, nice to see you solved your problem.
// Json
If you're running the main(..) method, wouldn't it be simpler to use Runtime.exec(..) to execute the other application, or do you have to share the same JVM ?
yup, sharing the same jvm. does it allow multiple classes run at the same time?