Forums Register Login

Retrieving classes of a package

+Pie Number of slices to send: Send
Hi all,
I want to retrieve all classes of a package from within a programme (not from a commandline with jar). I have to use JDK 1.1. I searched a lot but I can't find any resources on this.
Thanks for help
Helmut
+Pie Number of slices to send: Send
Hi Helmut
What u can do is import that package in ur program ,define the classpath for the jar files. This way u will be able to access any class of that package.
bye
pankaj

------------------
SCJP2
+Pie Number of slices to send: Send
Hi again,

Originally posted by pankaj bansal:
What u can do is import that package in ur program ,define the classpath for the jar files. This way u will be able to access any class of that package.


seems as if I ask my question not well. I need to know within a program which classes are in a package. Just like I can use jar -tf within the commandline. How can I do that?
Thanx
+Pie Number of slices to send: Send
You can execute an os command using this syntax:
Runtime.getRuntime().exec("cmd /K start run.bat");
or
Runtime.getRuntime().exec("notepad.exe");
SOOOO if you run the command and pipe the output into a file to read in later:
Runtime.getRuntime().exec("jar -tf whatever.jar > output.txt");
should work (I haven't tested this - sorry).
+Pie Number of slices to send: Send
Hi,
thanks for answering:

Originally posted by Cindy Glass:
SOOOO if you run the command and pipe the output into a file to read in later:
Runtime.getRuntime().exec("jar -tf whatever.jar > output.txt");


We can't get this information by using something like the reflection API?
Thanks
+Pie Number of slices to send: Send
Reflection is something used by objects. A jar file is not an object, it is something created outside of the JVM, so I do not know of any other way to do this.
Drove my Chevy to the levee but the levee was dry. A wrung this tiny ad and it was still dry.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 931 times.
Similar Threads
Difference between java.util.* and java.util.HashMap
Am i getting the difference between Protected and Default Correct ?
EXCEPTION problem
Protected(Access specifier)
Find All Implementing Classes
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 16:57:27.