Results 1 to 3 of 3

Thread: How to find package name by class name?

  1. #1
    Join Date
    Mar 2010
    Location
    Poland
    Posts
    3

    Default 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. #2
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,806

    Default

    It is nothing related with Spring

    Next time, just use Google,

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

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  3. #3
    Join Date
    Mar 2010
    Location
    Poland
    Posts
    3

    Default

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •