Getting 'binary name' of the package of  a given class

I needed this for a kind of dynamic class loader, where the binary name of the package of an object was required. What made it more complex is that the classpath of the object is not the local filesystem path, where the java executable was invoked (such as 'bin' in an eclipse project)
I searched the forum, and didn't find a solution that addresses all of these problems. Finally I came up with my own solution, and I'll share it with you (also because there might be some bright minds who can tell me it can be done much simpler (which I hope))
@SuppressWarnings("null")
public static String getPathFromClass(Class< ? > rootClass) throws FileNotFoundException
     String rootPath;
          // These are all the possible directories where the package root
          // exists (relative to where the java executable might be invoked).
          String systemPaths[] = {"bin", "."};
          File root = null;
          for (String systemPath : systemPaths)
               root = new File(systemPath);
               if (root.exists())
                    break;
          if (!root.exists() || !root.isDirectory())
               throw new FileNotFoundException("No package root found");
          rootPath = root.getAbsolutePath();
     String localPath;
     try
          localPath = new File(rootClass.getResource(".").toURI()).getPath();
     catch (URISyntaxException e)
          // Should never happen; Hack to prevent unjust error.
          localPath = "";
     if (!localPath.startsWith(rootPath))
          // What's going on ??
          throw new FileNotFoundException("Class' local path not inside package root");
     return localPath.substring(rootPath.length() + 1).replace(File.separatorChar, '.');
}Example:
main class is in c:\projects\test\bin\test\mj\foo\Main.class (package declaration sais "test.mj.foo".)
java.exe is executed from c:\projects\test\
calling this method with an instance of the Main class returns: "test.mj.foo".

As far as I can tell it just returns the package root (such as "c:\projects\test\bin"), but because of that, it does greatly simplify the first part of my function. Thanks.
String rootPath = new File(rootClass.getProtectionDomain().getCodeSource().getLocation().toURI()).getPath();
String localPath;
...A binary name (as mentioned in the Java Language Specification) is a representation of a fully qualified java class, such as "java.lang.String". A "binary name of a package" as I mentioned is just my way of meaning anything like "java.lang".

Similar Messages

  • Any Function module or BAPIs are available to get scheme name for the inter

    I have internal order no value in table  AUFK-AUFNR ,  and the internal order corresponding Scheme value is available in IMPR-PRNAM . Now I want to inner join both the tables to extract the data , but there is no common field . Is there any Function module or BAPIs are available to get scheme name for the internal orders?

    look at DB-VIEW  "V_IVP_OR".
    Regards,
    Laurent

  • How can i get my name on the finder bar?

    How do i get my name on the top right corner next to the search bar? I have OS X Mountain Lion 10.8.5

    System Preferences > Users & Groups
    Click the lock to unlock it, if you have to.
    Click "Login Options".
    Enable " Show fast user switching menu as" and select "Full Name".
    Best.

  • Getting login names of the users.

    Hi,
    Does anybody have an idea of getting login names of the user present in the plumtree.

    IPortletContext edk = PortletContextFactory.CreatePortletContext(Request, Response);
    IPortletUser IUser = edk.GetUser();
    userName = IUser.GetUserName();

  • HT1926 on install i get a message that the package has error code 2324. how do i fix this?

    Installing update I get a message that the package didn't install and that the error code is 2324. How do I fix this?

    The first thing I would suggest is for you to go to the folder containing your catalog, using your system browser. There will be a folder that has the extension .lrdata. Delete that folder, and then try to start Lightroom. If that doesn't work, replace your catalog with your most recent backup.

  • I am a student, and I wanted to know, please, what Adobe's software I get when I buy the package of the students(creative-cloud)?

    I am a student, and I wanted to know, please, what Adobe's software I get when I buy the package of the students(creative-cloud)?
    And another thing, how do I know if my computer is suitable for these programs in the current version?
    Thank you

    what is in the entire Cloud http://www.adobe.com/creativecloud/catalog/desktop.html
    MINIMUM System requirements for Cloud Programs... scroll down and check each program
    -http://helpx.adobe.com/creative-cloud/system-requirements.html

  • Name of the Package ?!?

    Hi
    While we opening any application there i a small window appears informing about the name of the software and about all the details and it automatically closes and go to particular software...
    I want to know wats the name of the package and the name of the class in java...
    If anybody know please tell me which class it used for...
    Thanx

    I'm confused by these two parts.
    While we opening any application there i a small
    I want to know wats the name of the package and the
    name of the class in java...Are you asking for the class which opened the small window, or the class which has "any application"? How do you know that either of them was written in Java?
    Not all applications are written in Java, so please clarify more than "any application" and "small window". Of those that were, most applications will have more than one class, and probably more than one package.

  • Get File name of the inbound file during mapping

    Scenario: to read the file name of the inbound file (which has date required for the mapping) during runtime.
    The requirement is to read the date of the inbound file (passed to the XI pipline by the file adapter) and populate the same in the outbound mapping structure.
    Any idea about how to do this?
    (I went through few options of using java.util.map. not successful yet)

    Hi Anand,
    I posted the same question a time ago, without any help....
    Can I find out the full filename of input file in message mapping?
    Posted: Nov 23, 2004 1:00 PM
    I have in XI 2.0 the following scenario :
    In the inbound fileadapter I read my input file. The filename of the input file is part fixed, part variable (Like INDATA01.txt, INDATA03.txt, etc).
    So in my Adapterconfiguration, I specify the filename with a wildcard (INDATA*.txt).
    What I now want to do, is in my Message Mapping use the full filename , so I can do something different for every filenumber. Is there a way where I can get the full filename available in my message mapping (I did not find the filename in the XML in the message trace).

  • How to get file name of the form attachment?

    Hi,
    is there anybody who is able to help me with the following problem???
    I started my process from Workspace ES and as a first step I attached one locale file (IMG.JPG or IMG.TIF e.g.) as a form attachment. I used "Attachments" bookmark in the Workspace ES.
    I need to get file name of attached file in the process!!!
    I tried to use "getTaskAttachments" component to get file name of form attachment but without success. This component successfully obtained attached file an stored it in the variable (type list, subtype document) but didn't produce all file attribute informations such as basename or Content Type:
    Is there some possibility to obtain file name (including file extension) by using "standard" tools and components of ALC?
    Thanks for your suggestions.

    Hi LekomDev,
    I faced the same situation some time back and this is what I know.
    Based on the file type few of the attributes will or will not be populated. (This is what the official documentation says about Document attributes)
    The file name that you are looking for would mostly be in 'name' attribute of Document object. The 'wsfilename' attribute is the atrribute which gets used to show the file name into Attachments tab of the workspace.
    So, if you are just interested in knowing the filenames then 'name' attribute is the place that you are looking for.
    But if you are trying to solve an issue in which Attachments against a Task isn't showing the filenames properly then you would need to copy the 'name' attribute value into 'wsfilename' attribute and then the Attachmetns against a Task would have the correct names.
    Tip: Use the Record and Playback option of the workbench to inspect the Document variable and you would see all of the values for a Document variable at desired step in your orchestration.
    hope this helps,
    cheers,
    Parth Pandya
    Blog: http://livecyclekarma.wordpress.com

  • Output error:the name of the package "greet" does not reflect the location of this file...

    output error: The name of package 'greet' does not reflect the location of this file. Please change the package definition's name inside this file, or move the file. C:\Documents and Settings\Igal\My Documents\meiran\greet\Greeter.as
    I keep on recieving this output error although my source path is set to C:\Documents and Settings\Igal\My Documents\meiran\greet.
    any suggestions why this happens?

    The classpaths you define in your Flash software tell the compiler where to look when it needs to find a class.  According to your as file, the very top line indicates the Greeter.as file should be at a location specified by the path...
    one-of-your-classpaths\com\example\quickstart\
    So if one of your classpaths is:  C:\Documents and Settings\Igal\My Documents\meiran\greet\
    and you placed the file in the greet folder, then in your AS document you should not have the "com\example\quickstart" and your import statement in the fla should not be using that (should just be... import Greeter;)

  • File-2-Proxy: Get file name in the inbound proxy?

    Hi,
    I need to know the file name in the inbound proxy. After a search I found that's possible mapping the file name to the target structure as it's explained in that link: [http://www.sdn.sap.com/irj/scn/weblogs;jsessionid=(J2EE3417200)ID1731350750DB00274596951164745615End?blog=/pub/wlg/2664]
    But I need to know if there is another way to access the file name in the inbound proxy without modifying the mapping.
    Thanks.

    this is possible by a dynamic configuration (there is no other easy way)
    some references -
    http://www.sdn.sap.com/irj/scn/weblogs;jsessionid=(J2EE3417500)ID1159980350DB00296046510040545862End?blog=/pub/wlg/13704
    the idea is to get the file name in runtime using the dynamic conf code and poulating it to any field that will be part of the proxy message

  • Getting only name of the physical disk from cluster group

    hi experts,
    i want to know the name of my cluster disk example - `Cluster Disk 2` available in a cluster group. Can i write a command something like below.
    Get-ClusterGroup –Name FileServer1 | Get-ClusterResource   where  ResourceType is Physical Disk
    Thanks
    Sid
    sid

    thanks Chaib... its working.
    However i tried this
    Get-ClusterGroup
    ClusterDemoRole
    | Get-ClusterResource
    | fl name
    |  findstr
    "physical Disk"
    which is also working.
    sid

  • How to get file name on the base of extension

    hi
    reply me
    how to get the filename on the base of extension from the
    current directory......
    for example
    i create file with the "igg" extension and save in the folder
    where the exe file of director save....
    i want when exe run then exe file read filename of the
    define( "igg" ) extension with out path just name of the file with
    igg extension
    tel me how
    regards
    farhana khan

    Here's a solution that requires no xtras:
    on GetFilesWithExtension(aFolderPath, aExtension)
    -- INPUT: <aFolderPath> should be a valid string
    folder path
    -- <aExtension> may be a string file extension,
    without the
    -- dot. For example: "txt" or "igg"
    -- OUTPUT: Returns an error symbol or a linear list of file
    names
    -- in the given folder. If an extension is given, only
    -- files with the given extension will be listed. If not,
    -- all files and folders will be listed.
    vFileList = []
    if not stringP(aFolderPath) then
    return #stringPathExpected
    end if
    vIgnoreExtension = not stringP(aExtension)
    vDelimiter = the itemDelimiter
    the itemDelimiter = "."
    n = 0
    repeat while TRUE
    n = n + 1
    vFileName = getNthFileNameInFolder(aFolderPath, n)
    if vFileName = "" then
    exit repeat
    end if
    if vIgnoreExtension then
    vFileList.append(vFileName)
    else if the last item of vFileName = aExtension then
    vFileList.append(vFileName)
    end if
    end repeat
    the itemDelimiter = vDelimiter
    return vFileList
    end GetFilesWithExtension
    You can also use
    Buddy API's baFileList,
    which allows you to do wildcard searching.

  • Can't find code for std web dynpro app but can seeit's name in the package?

    Hi All,
    We're using ECC6 and EPP 7.01 SP4.
    We've recently uploaded some new packages.  Within one is a Portal Buyer role (1.4).  I would like to access the code for one of the standard web dynros.  I retrieved the name of the application from the iview in the portal.  But when I input the application name in se80, it said it didn't exist.  But yet when I look at the package, I can find the application I want in there but it's not in the interface folder, it's in the Applicat. folder.
    I'm new to web dynpro so apologies if it's a stupid question but.. Why is it like this?  What is the difference between an interface and an application?  Is it possible to access the code of the application?
    Package = MMPUR_UI_VIEW
    Application name = MMPUR_UI_PR_APP
    Any help, would be great as I'm totally stumped.
    Thanks in advance,
    Liz.

    Found the component name from the application.  The application is just a link to a component/interface.

  • Report that gets full name from the users id in the computer name

    I don't even know if this is possible, but I am finding that quite often of late I am needing to get the users full name from the computer name.
    We have a standard where a computer name is in this format XXXXXXXUSERID.
    Is there a way to get the Full name from the USERID that is in the computername (not last logged on user).
    I am fairly sure that I might be able to work it out in SQLSMS but I really need it on the web reports form SCCM.
    If anyone has any ideas please let me know.

    Thanks, I want to add it to most my reports but this is the main one that I am using right now due to an audit. 
    SELECT DISTINCT
    CS.Name0 AS 'Computer Name', CS.Domain0 AS 'Domain', CS.UserName0 AS 'User', BIOS.SerialNumber0 AS 'Bios serial',
    SE.SerialNumber0 AS 'System Enclosure serial', CS.Manufacturer0 AS 'Manufacturer', CS.Model0 AS 'model', OS.Caption0 AS 'OS',
    RAA.SMS_Assigned_Sites0 AS 'Site', RAM.TotalPhysicalMemory0 AS 'Total Memory', SUM(ISNULL(LDisk.Size0, '0')) AS 'Hardrive Size',
    SUM(ISNULL(LDisk.FreeSpace0, '0')) AS 'Free Space', CPU.Name0 AS [CPU Name]
    FROM dbo.v_GS_COMPUTER_SYSTEM AS CS RIGHT OUTER JOIN
    dbo.v_GS_PC_BIOS AS BIOS ON BIOS.ResourceID = CS.ResourceID RIGHT OUTER JOIN
    dbo.v_GS_SYSTEM AS SYS ON SYS.ResourceID = CS.ResourceID RIGHT OUTER JOIN
    dbo.v_GS_OPERATING_SYSTEM AS OS ON OS.ResourceID = CS.ResourceID RIGHT OUTER JOIN
    dbo.v_RA_System_SMSAssignedSites AS RAA ON RAA.ResourceID = CS.ResourceID RIGHT OUTER JOIN
    dbo.v_GS_X86_PC_MEMORY AS RAM ON RAM.ResourceID = CS.ResourceID RIGHT OUTER JOIN
    dbo.v_GS_LOGICAL_DISK AS LDisk ON LDisk.ResourceID = CS.ResourceID RIGHT OUTER JOIN
    dbo.v_GS_PROCESSOR AS CPU ON CPU.ResourceID = CS.ResourceID RIGHT OUTER JOIN
    dbo.v_GS_SYSTEM_ENCLOSURE AS SE ON SE.ResourceID = CS.ResourceID
    WHERE (LDisk.DriveType0 = 3)
    GROUP BY CS.Name0, CS.Domain0, CS.UserName0, BIOS.SerialNumber0, SE.SerialNumber0, CS.Manufacturer0, CS.Model0, OS.Caption0, RAA.SMS_Assigned_Sites0,
    RAM.TotalPhysicalMemory0, CPU.Name0
    What I really want to do is add another column called owner that just has the UID in it, I will then try to pull the users full name into another column.. hopefully I am not biting off more then I can chew with this but i have thousands of records and i
    will be forced to export to excel or something then look up all the names if I can't do this...

Maybe you are looking for

  • Installing/Uninstalling Adobe 11.0.03

    1) Whenever I try to open a pdf file, I receive an error message 2) One of the suggestions on the error message was to download the latest version of Adobe Reader 3) Went to the Adobe site...downloaded the latest version...and was told the latest ver

  • My Creative Cloud application does not open correctly, I don't understand why ! the window open, but there is nothing inside... Why ?

    Here is a Screencapture of my Creative Cloud application when I open it ! Any idea of where I can search to resolved the problem ? I've reinstalled but nothing change ! Thank you for your help...

  • Font problem in Safari

    Some pages in Safari show up as gibberish. This started happening after I cleaned out my font library. I tried re-installing the system but I'm having the same problem. Anyone have any ideas? Thanks.

  • Adobe Reader 10.1.2 fails to open any PDFs

    Like so many others, I accepted the upgrade to Adobe Reader 10 and now I cannot open PDFs on the internet. The error message I receive is: "There is a problem with Adobe Acrobat/Reader. If it is running, please exit and try again. (1:1)" This message

  • Oracle Fulfillment Server failing

    listener error coming while starting database and connecurent nodes these are the errors . TNS-12224: TNS:no listener TNS-12541: TNS:no listener TNS-12560: TNS:protocol adapter error TNS-00511: No listener and While starting Forms server node this se