0

Is there a way to know which java package a class is related to through a line of command? For exemple, I would like to print out the package of the class Integer which is java.lang.Integer

Thanks

Aod Ren
  • 681
  • 1
  • 8
  • 17
  • This is much more complicated than you make it sound. What if there's 2 classes named `Integer` and they differ by their package? What about classes inside 3rd party JARs? If you're using an IDE, there are solutions. – Tunaki Jan 10 '16 at 10:11
  • You could scan a hierarchy of jars and see which contain a certain foo.class using any archiving utility that supports zip files – Marged Jan 10 '16 at 10:13
  • What do you mean "through a line of command" ? This is easily done in Java – Aaron Jan 10 '16 at 10:13
  • I mean through a System.out.println But from your answers i assume my question doesn't make much of a sense. I know i can see the package through an IDE. – Aod Ren Jan 10 '16 at 10:16

2 Answers2

2

Edit : there's a class.getPackage() method I didn't knew about.

System.out.println(Integer.class.getPackage().getName());
Aaron
  • 24,009
  • 2
  • 33
  • 57
0

If I understand correctly you want to be able to search for a class using its SimpleName and then print the package name. Or at least print all possible matches (found in several packages).

If this is the case you can leverage the snippet (found here) to create a utility yourself and execute from command line. This might be a bit slow though.

Community
  • 1
  • 1
theo
  • 915
  • 1
  • 9
  • 28