How to find the location of java class files at runtime?

Does anyonw have an idea how to get the file name of a java class given the binary name?
I mean how can I get the file name for my class myPackage.myClass?
I am looking for a function which takes "myPackage.myClass" as input and returns
"c:\\javaprojects\\myPackage\\myClass.class".
I tried to do it with the LassLoader class but it did not work. Does anyone have an idea if the Java core API already has a function which does that?
Thanks, Bernhard

Hi ,
It is a simple SAMPLE code , you think and build a logics to handle all classes.
Try this sample, It doesn't handle the inner classes you put logic to handle the logics for inner classes.
The inner class format is it contains the character $ in the File location but inside the code you put "." instedad of "$" you to find out or put trials.
package pkg1;
import java.io.* ;
import java.util.* ;
import java.util.zip.* ;
public class ClsB {
     private static Vector clsPaths ;
     public static Vector getPaths() {
          if( clsPaths == null ) {
               String paths = System.getProperty( "java.class.path" ) ;
               // In linux or solarise use the following
               // StringTokenizer st = new StringTokenizer( paths , ":\n" ) ;
               StringTokenizer st = new StringTokenizer( paths , ";\n" ) ;
               clsPaths = new Vector() ;
               while( st.hasMoreTokens() ) {
                    String path = st.nextToken() ;
                    File f = new File( path ) ;
                    if( f.exists() ) {
                         try {
                              f = f.getCanonicalFile() ;
                              clsPaths.add( f ) ;
                         }catch( IOException ioe ) { }
          return clsPaths ;
     public static String findClassPath( String fullClassName ) {
          Vector v = getPaths() ;
          for( int i = 0 ; i < v.size() ; i++ ) {
               File f = ( File ) v.get( i ) ;
               String path = findIn( f , fullClassName ) ;
               if( path != null )
                    return path ;
          return null ;
     static boolean isJar( File jar ) {
          if( jar.isDirectory() )
               return false ;
          try {
               ZipFile zf = new ZipFile( jar ) ;
               return true ;
          } catch ( ZipException ze ) {
               // It is not a jar file
               // you handle this
          } catch ( IOException ioe ) {
               ioe.printStackTrace() ;
          return false ;
     static String findIn( File dirOrJar , String clsName ) {
          if( isJar( dirOrJar ) ) {
               // It is something different because the class inside the jar file
               // Simply I return the jar file location and the entry name ,
               // but you put action what you want
               if( isInsideJar( dirOrJar , clsName ) ) {
                    // All archieve file using the path separator is '/'
                    return dirOrJar.getPath() + "!" + clsName.replace( '.' , '/' ) + ".class" ;
          } else {
               File f = new File( dirOrJar , clsName.replace( '.' , File.separatorChar ) + ".class" ) ;
               if( f.exists() ) {
                    return f.getPath() ;
          return null ;
     static boolean isInsideJar( File jar , String clsName ) {
          try {
               ZipFile zf = new ZipFile( jar ) ;
               // All archieve file using the path separator is '/'
               ZipEntry ze = zf.getEntry( clsName.replace( '.' , '/' ) + ".class" );
               return ( ze != null ) ;
          } catch ( ZipException ze ) {
               ze.printStackTrace() ;
          } catch ( IOException ioe ) {
               ioe.printStackTrace() ;
          return false ;
     public static void main(String[] args) {
          System.out.println( findClassPath( "pkg1.ClsB" ) );
          System.out.println( findClassPath( "pkg1.pkg2.ClsA" ) );
}

Similar Messages

  • How to find the location of controller class file on the server

    Hi OAF Experts,
    We have a extended controller in which we are making some changes. We have compiled the java file.
    Now we want to deploy the .class file on the server. When we search on the server where we need to deploy the class file, we find two to three paths. Is there a way from which we can decide which path is actually referred ?
    Is there a front end page available from where we will be gettng these details??
    Regards
    Samarth

    Hi,
    You can get the complete path from front end.
    On 'About this Page', there is a section for 'Business Components'. When you expand that, you can see all the controllers used with complete path.
    --Sushant                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • HOW TO SEARCH THE LOCATION OF A PARTICULAR FILE(say a doc file) IN JAVA

    JAVA CODE FOR FINDING THE LOCATION OF A PARTICULAR FILE(say a doc file)

    Well you can write a recursive/iterative code using methods provided by
    java.io.File class.
    However,there are few customized frameworks coming up which can to job for you please have a look at.
    https://filesearch.dev.java.net/
    else where if you wanna build up your own solution the below POST could be useful.
    http://en.allexperts.com/q/Java-1046/desktop-file-search-1.htm
    or you might go ahead and use source of file search utility where an implementation is provided in the below article
    http://jdj.sys-con.com/read/36412.htm
    Hope this might help :)
    REGARDS,
    RaHuL

  • How can find the location of my iPad when location services is off?

    How can find the location of my iPad when location services is off?

    If you're wanting to know if you can locate your iPad though iCloud, without Find my device enabled and without power, you won't be able to locate it.

  • HT1222 How to find the location service?

    How to find the location service??

    new File("winmysqladmin.exe");This creates a File object that refers to a hypothetical file called "winmysqladmin.exe" in the current working directory. It is quite possible that there is no such file, that is why File has an exists() method.
    If you want to search the entire file system for a file, you have to do just that -- search. Start looking at the API documentation for File. You will find a static listRoots() method that gives you an array of the root directories of available drives. You will also find methods like isDirectory(), which tells you whether a file is a directory, and listFiles(), which gives you an array of files in a particular directory. Then you have to search the directory trees recursively, bearing in mind that you may encounter more than one file with that name.

  • How to Find the Location in Google Maps using Latitude and Longitude

    Hai,
    I need to find the Location from Google Maps, which is match with the Latitude and Longitude values we are sending.
    This will be done by using pure java class i need, can anyone having the sample code for this.
    It's Urgent, please help me
    Expecting replies...

    Yes we were having the performance issues when it is getting locked? in this what i want to know
    why it happens suddenly?
    or what package this piece of code is calling?
    or is there any possiblity of system will degrade the performance like sys user etc...?
    where exactly i found the root cause for further analysis?
    so that next time onwards if particular objects is locking we come to know why it happens is there any logical false or how do we eliminate this issue last time?
    coz in our environment sometimes most of lockings are from the same table?
    pls let me know where i have to concentrate for debug and how to troubloshoot and reslove this
    sorry for the inconvience.. i m expecting the answer from here. if anybody wants some more info i ll let him know.
    as of till now i got some docs i start to read this.
    Regards
    M.Murali..
    Note: will system/sys degrade the performance ?if so how ?

  • How to find the location of a particular font in the framemaker book?

    Hi All,
    please help me in finding the location of a particular type of font in the framemaker book. I was using the following procedure to find out earlier:
    Find > Character Format > (set the character format) > Search.
    Now I am unable to locate a particular type of font using the mentioned procedure.
    Please help me out.
    Thanks in adnavce,
    Mindevil

    This assumes that the font instance being searched for is an override:
    Click in some text in one of the book files.
    Edit > Find/Change
    [ Character Format ...]
    This pops up a Character Format dialog.
    Assuming you are on Windows:
    [Ctrl]+[Shift]+[F8] to set everything to As-Is/blank.
    In Family:, select the font being sought. [Set]
    Back in the Find dialog...
    Look in: <*> Book
    [Find]
    If the font instance is part of a Paragraph Format or Character Format, you can search by Para Tag name or Char Tag name (which is yet another reason why overrides are a problem).
    Or you can save out all the book files as MIF and search with a plaintext editor, but that requires a nominal knowledge of MIF.
    I might add that steps 1-3 above are covered in FM7.1 Help (and presumably the printed manual back then), but are absent for FM9, and I'm guessing that they never returned in later versions either.

  • MY IPHONE HAS BEEN STOLEN, LAST MARCH 10 AND NOW A TELESERVICE TEXTED ME THAT IT HAS BEEN LOCATED AND THEY GAVE ME A LINK TO APPLE SUPPORT SERVICE BUT I CAN'T ENTER THE SITE. PLEASE HELP ME KNOW HOW TO FIND THE LOCATION OF MY LOST PHONE

    HOW TO KNOW THE LOCATION OF MY LOST PHONE IT HAS BEEN FOUND ALREADY BUT I DON'T KNOW WHERE TO GO

    Please stop typing in caps. It is difficult to read and rude, Caps are considered shouting on the web.
    Odds are that is a scam.
    Post more details, such as phone number and we'll confirm if it is a scam or not.

  • How to access variables declared in java class file from jsp

    i have a java package which reads values from property file. i have imported the package.classname in jsp file and also i have created an object for the class file like
    classname object=new classname();
    now iam able to access only the methods defined in the class but not the variables. i have defined connection properties in class file.
    in jsp i need to use
    statement=con.createstatement(); but it shows variable not declared.
    con is declared in java class file.
    how to access the variables?
    thanks

    here is the code
    * testbean.java
    * Created on October 31, 2006, 12:14 PM
    package property;
    import java.beans.*;
    import java.io.Serializable;
    public class testbean extends Object implements Serializable {
    public String sampleProperty="test2";
        public String getSampleProperty() {
            return sampleProperty;
    }jsp file
    <%@ page contentType="text/html;charset=windows-1252"%>
    <%@ page import="java.sql.*,java.util.*"%>
    <html>
    <head>
    <title>Schedule Details</title>
    </head>
    <jsp:useBean id="ConProp" class="property.testbean"/>
    <body>
    Messge is : <jsp:getProperty name="msg" property="sampleProperty"/>
    <%
      out.println(ConProp.sampleProperty);
    %>
    </body>
    </html>out.println(ConProp.sampleProperty) prints null value.
    is this the right procedure to access bean variables
    thanks

  • How to convert dll to a java class file?

    Hi folks:
    I have some DLLs in VB and C++ and I wanna to convert them to a java class file. Does anybody know if exist a sw or easy way to do it?
    thanks
    Autair

    Well, I believe you could write JNI to call the functions in the DLLs, although I wouldn't recommend it. (You'd have a non-portable, fragile result.)

  • How to find path from within java class where .class file is located

    I have a situation where my Servlet is running.
    I need to access a text file which is locted in the same
    place where the .class file for this Servlet is located.
    I cannot specify absolute path in my java file.
    I am in Windows platform.
    My filename is specified as
    File("myfile.txt");
    the problem is it says file not found.
    how do i fix this prob?
    thanks in advance

    String filename="/relative_path/file_name.txt";
    try {
       //static method approach
       InputStream is = YourClassName.class.getResourceAsStream(filename);
       //non-static method approach
       InputStream is = getClass().getResourceAsStream(filename);
    } catch (IOException e) { ... }tajenkins

  • How do i find the location of Oracle password file in the HDD

    we giv the location of the password file while we use the orapwd command to create one.
    later if we forget the location of the password file (incase it is not at the default location) then is there a way to find it or do we just create a new password file?
    secondly, for oracle to use the password file we giv the remote_login_passwordfile='EXCLUSIVE' in the parameter file. wat tells oracle the location of the exact password file??
    Thanks
    Arvind
    Edited by: iinfi on Sep 29, 2008 12:15 AM

    The default location are OS dependant.
    On Unix/Linus it is under $ORACLE_HOME/dbs
    On Windows, it is under %ORACLE_HOME%/database
    To change the default location, nothing inside database, but :
    On Unix/Linux, you have to create a symbolic link for that file to the target location
    On Windows, you have to change env variable (regedit) ORA_PWFILE and ORA_SID_PWFILE
    So, you have to check this setting for the real password file location.
    Nicolas.

  • How to find the location of mac book if i lost it

    i lost my mac book air. Is it possible to see the location of my mac book air ?

    Welcome to the Apple Support Communities
    If you had turned on Find my Mac on the MacBook Air, just open http://www.icloud.com, log in with your Apple ID and select "Find my iPhone".
    That's the only way to find your MacBook. If it's not connected to the Internet or if you haven't turned on Find my Mac, you won't be able to track it

  • How to find the location of something I installed?

    I can see the app in my system information under installations but I can't seem to find it anywhere on my hard drive. Can you please help?

    See if you can find the file using this program. If you go Finder/View/Show Path Bar, it will show you where it is located.
    EasyFind – Spotlight Replacement

  • How to find the executables for OWB Client, Design and Runtime Repositories

    Hi Guys,
    I have installed OWB 10G in the my local desktop (in D Drive). From the start menu, I can see the menu options for OWB Client, OWB Design Repository and OWB Run time Repository. If I want to get that execuatbles from which location can I find out. All the menu options are pointing out into d:\OWB Home \....\bin\launch.exe, but when we hit launch.exe nothing is displayed on the screen. can anyone give their suggestions pls
    Regards
    Kishan

    launch.exe is the executable but if you look at the lnk files in your start menu the launch exe is followed by two parameters where the last one points to a specific cl file (I'm guessing short for command line) in the same bin directory that also contains a number of parameters. Here all the java jar files are listed that are needed to launch the specific component and how much memory the application can/may use.
    So you won't find a classic windows executable if that is what you are looking for. But why are you searching for this in the first place since you can just copy the shortcut/lnk file if you want shortcuts in other places?

Maybe you are looking for

  • Help ~~ Cannot compile servlet program

    I have recently written a servlet program. When I compile the program (let's say "HelloWorld.java"), I've got the following error message: package javax.servlet does not exist I've download the class files and set the classpath already. Have I missed

  • Suggestion on exposing ECC 6 Prod WebGUI for external vendors!

    Hi, Our requirement is provide access to few transactions of our Production ECC 6 (EhP4) to external vendors and currently there are no Portal business package for these transactions. Re-development of these transactions could take a long time becaus

  • Classpath for J2SDK 1.4.1

    Hello, I'm a beginner to Java and I'm using Mandrake Linux 9.0 and J2SDK 1.4.1. I would like to ask how to set the class path for the SDK? Meanwhile, I always get this error message when compilering a java file that uses class packages.(i.e. javax.sw

  • CATS WBS Issue

    Hi All, In CAT2 transaction, if I manually create a data entry by copying the wbs element from the worklist and  save then if I  execute the program  "DPR_CATS_CPR_TRANSF" the confirmation time is reflected in the PS system. But if I upload data thro

  • SGE2010 stacking versus link aggregation

    Can someone provide an answer regarding stacking the SGE2010 switches versus link aggregation if greater than 1 Gb connectivity is required between individual switches? Currently have several switches in a stack configuration but would like to increa