Announcement Announcement Module
Collapse
No announcement yet.
How to find package name by class name? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to find package name by class name?

    Hi all,

    Is it possible to find a package name by a class name?

    Code:
    String className = "MyClass";
    String packageName = SomeClass.SomeMethod(className);
    
    System.println(packageName);
    I need a package name because I would like to use it to set up table name in Hibernate NamingStategy. Perhaps you know other trick to optain this purpose?

    Best,
    Cezary

  • #2
    It is nothing related with Spring

    Next time, just use Google,

    Code:
    ObtainingPackageName o = new ObtainingPackageName();
    packageName = o.getClass().getPackage().getName();

    Comment


    • #3
      OK,

      but I looking for method which returns package name by a class name (String) not by a object of class.

      In NamingStrategy I've got only a class name as a String. I have got not to the object of this class...

      Best,
      Cezary

      Comment

      Working...
      X