Find directory in location relative to class

Is there a better way to do this?
I have a package with a main class called 'RainfallSeriesTranslator.bin.ui.Launcher' and some methods in a sub-directory called 'RainfallSeriesTranslator.bin.methods'. The 'methods' directory will always be in the same relative location to 'ui.Launcher', but the package could be in any location on the users machine. My intention is to develop a number of classes and to drop them into the 'methods' directory as and when, so 'Launcher' needs to be able to dynamically (or at least at compile time) list out the contents of the 'methods' directory as strings into an array called 'contents'.
My earlier attempts got it to launch from Eclipse, but not from the command prompt. I think I have traced this error to my use of the working directory as a prepend to the 'methods' directory.
The following is a successful work-around (see 'getMethods'). My idea was to get the URL of 'Launcher' as a 'bearing' and to change the relevant references to point to 'Methods'. It works for WinXP and Mac OS X.
However, it looks long-winded. Is there a better way to do it? (I have left the string manipulations uncondensed for readibility). Would this fall over on another (common) operating system?
package ui;
import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
public class Launcher {
     private final static String name = "RainfallSeriesTranslatorPanel";
     private final static String[] methods = getMethods();
     private final static String fileExt = ".class";
     public static void main(String[] args) {
          new Panel(name, methods);
     public static String[] getMethods() {
          String fileSeparator = System.getProperty("file.separator");
          //Find the URL of this class
          String str1 = Launcher.class.getResource("Launcher.class").toString();     
          //Remove the "file:/" part of the URL
          String str2 = "file:/";
          String str3 = str1.replace(str2, "");
          //Replace the last part of the filepath
          String str4 = "ui/Launcher.class";          
          String str5 = "Methods";
          //Assemble the absolute filepath name with system specific file separators
          //Works on WinXP and Mac OS X
          String str6 = str3.replace(str4, str5);     
          String methodDirectory = fileSeparator + str6.replace("/", fileSeparator);
          File dir = new File(methodDirectory);
          ArrayList <String> methodsAL = new ArrayList<String>();
          FilenameFilter filter = new FilenameFilter() {
                  public boolean accept(File dir, String name) {
                      return name.endsWith(fileExt);
          String []contents = dir.list(filter);
          for (int i = 0; i < contents.length; i++){
               methodsAL.add(contents.replace(fileExt, ""));
          return methodsAL.toArray(new String[methodsAL.size()]);
     public String getPanelName() {
          return name;
     public String getFileExtensionName() {
          return fileExt;
}PS Its curious that Mac OS X needs the absolute path to start with a file separator, but Windows seems to ignore it - possibly because it occurs before a 'C:' type of reference.  I don't have an explanation, I'm just observing something that appears to work.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Thanks guys,
The following works as expected for WinXP and Mac OS X.
package ui;
import java.io.File;
import java.io.FilenameFilter;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
public class Launcher {
     private final static String name = "RainfallSeriesTranslatorPanel";
     private final static String[] methods = getMethods();
     private final static String fileExt = ".class";
     public static void main(String[] args) {
          new Panel(name, methods);
     public static String[] getMethods() {
          //Find the URI of the methods directory
          URI methodDirectory = null;
          try {
               methodDirectory = Launcher.class.getResource("/methods").toURI();
          } catch (URISyntaxException e) {
               System.out.println("RainfallSeriesTranslator.src.ui.Launcher cannot find the directoty 'methods'");
               e.printStackTrace();
          File dir = new File(methodDirectory);
          ArrayList <String> methodsArrayList = new ArrayList<String>();
          FilenameFilter filter = new FilenameFilter() {
                  public boolean accept(File dir, String name) {
                      return name.endsWith(fileExt);
          String []contents = dir.list(filter);
          for (int i = 0; i < contents.length; i++){
               methodsArrayList.add(contents.replace(fileExt, ""));
          return methodsArrayList.toArray(new String[methodsArrayList.size()]);
     public String getPanelName() {
          return name;
     public String getFileExtensionName() {
          return fileExt;
}Chuck, thanks for the suggestion, but I had trouble with anything that had a reference to the working directory (System.getProperty("user.dir")).  The problem, I think, was that the class will not necessarily be in the working directory.  I can only offer an observation and an inference, not an explanation, but this meant that I could launch 'launcher' from Eclipse (presumably because Eclipse set the working directory to where the package was) but I could not launch it from terminal or command prompt (presumably because the working directory was set to default).  See  [http://forum.java.sun.com/thread.jspa?threadID=5289014]  for an earlier post.
Now for a dummy question;  what does URL and URI stand for?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • Hi, using iphoto 6, i suddenly lost albums: they are still in the directory, but no pictures in some albums.Using finder, I can locate the pictures and even get preview. But impossible to import them. Anyone can help? thanks

    Hi, using iphoto 6, i suddenly lost albums: they are still in the directory, but no pictures in some albums.Using finder, I can locate the pictures and even get preview. But impossible to import them. Anyone can help? thanks

    Try these in order - from best option on down...
    1. Do you have an up-to-date back up? If so, try copy the library6.iphoto file from the back up to the iPhoto Library allowing it to overwrite the damaged file.
    2. Download <a href="http://www.fatcatsoftware.com/iplm/"><b><u>iPhoto Library Manager</b></u></a> and use its rebuild function. This will create a new library based on data in the albumdata.xml file. Not everything will be brought over - no slideshows, books or calendars, for instance - but it should get all your albums and keywords back.
    Because this process creates an entirely new library and leaves your old one untouched, it is non-destructive, and if you're not happy with the results you can simply return to your old one.
    3. If neither of these work then you'll need to create and populate a new library.
    To create and populate a new *iPhoto 6* library:
    Note this will give you a working library with the same Rolls and pictures as before, however, you will lose your albums, keywords, modified versions, books, calendars etc.
    Move the iPhoto Library to the desktop
    Launch iPhoto. It will ask if you wish to create a new Library. Say Yes.
    Go into the iPhoto Library on your desktop and find the Originals folder. From the Originals folder drag the individual Roll Folders to the iPhoto Window and it will recreate them in the new library.
    When you're sure all is well you can delete the iPhoto Library on your desktop.
    In the future, in addition to your usual back up routine, you might like to make a copy of the library6.iPhoto file whenever you have made changes to the library as protection against database corruption.

  • Finder displaying some location in chinese font

    Hi,
    First time poster here. I have done an extensive search of the community but am struggling to find anything that specifically relates to me. Anyway, I ran the upgrade to Yosemite over the weekend and I am now getting some location in my Finder displayed in Chinese fonts. There is no pattern to what changes and upon reboot it may change what is shown in the Chinese characters. I have included a screenshot below:
    Anything I can do to fix this?

    Here's a funny thing - I thought that the fix of changing to one language had worked. It has, for most views.
    However, when I look at the finder under 'Today', 'Yesterday' or 'Past Week', I find quite a lot of files either have their names or types in Japanese - when I look at the same file in its home directory, the language is back to English.
    I've tried rebooting and re-starting Finder, but it seems a pretty hard error.

  • How can I get the jar location of a class (the -Xbootclasspath case)?

    Hi
    I'm using -Xbootclasspath/a to append a jar into the "ring 0" of VM. Inside my class, I want to find out the location of the jar so that I can find other resources that's deployed along with it. How can I do that? I try the standard getProtectionDomain().getCodeSource().getLocation() way but it seems a class in bootpath returns null at the second method.
    Currently I have to manually feed the path into the app using an environment variable, but I'd like to know if there's a better solution.
    Thanks
    Weijun

    This is not exactly the answer that you are looking for but If your are interested into the BOOTCLASSPATH value, you can get it with JMX.
    RuntimeMXBean mx = ManagementFactory.getRuntimeMXBean();
    System.out.println("BOOTCLASSPATH:\n"
         + mx.getBootClassPath());Bye.

  • In which directory should i keep java class files in oracle apps

    hi
    I have one problem, In which Top & directory should i keep java class files in oracle apps
    krishna

    Hi
    By itself its available in oracle\visappl\au\11.5.0\java\
    thats were the location needs to be placed in the apps.zip.
    Thanks
    Riyas

  • Find Tax Return Locations for all Accounting needs, File Tax return......

    Hi dear friends
    Find Tax Return Locations for all Accounting needs, File Tax return, Business Accounting, Payroll, Income Tax, Property Tax, State Tax.
    Find a qualified local Tax Professional, CPA, Accounting Firm,  Accountant, Financial Planning from most widely used Directory.
    Our services are -- irs tax help, accounting, taxes, irs, tax debt help, payroll, income tax, property tax, tax attorney, tax, cpa, accountants, tax help, tax return, business tax return, free tax help, estate tax,
    More information visit below here --
    [FINDTAXRETURN|http://www.findtaxreturn.com/]
    Cheers
    Admin

    I have already received the TT application for 2012 filing.
    Have you checked at their website?
    http://www.turbotax.com/lp/ty11/ppc/hp.jsp?cid=ppc_gg_b_stan_dk_us_hv-trbtx-mn&a did=18494275668&skw=TurboTax&kw=turbotax&ven=gg&

  • Find Tax Return Locations for all Accounting needs, File Tax return, Busine

    Hi dear friends
    Find Tax Return Locations for all Accounting needs, File Tax return, Business Accounting, Payroll, Income Tax, Property Tax, State Tax.
    Find a qualified local Tax Professional, CPA, Accounting Firm,  Accountant, Financial Planning from most widely used Directory.
    Our services are -- irs tax help, accounting, taxes, irs, tax debt help, payroll, income tax, property tax, tax attorney, tax, cpa, accountants, tax help, tax return, business tax return, free tax help, estate tax,
    More information visit below here --
    [FINDTAXRETURN|http://www.findtaxreturn.com/]
    Cheers:)
    Admin:)

    I have already received the TT application for 2012 filing.
    Have you checked at their website?
    http://www.turbotax.com/lp/ty11/ppc/hp.jsp?cid=ppc_gg_b_stan_dk_us_hv-trbtx-mn&a did=18494275668&skw=TurboTax&kw=turbotax&ven=gg&

  • Cannot locate custom controller class after applying OIE.K  patch.

    Hi,
    I am trying to search all the region level personalizations(on Update Allocations Page in iExpenses while creating Expense Reports) to find out where our custom controller class is being called(it was personalized at site level). But no luck until now.
    Nevertheless, we were able to locate our custom controller class in an instance where the OIE.K oracle patch was not applied. Seems like after applying this patch, the seeded region names are changed too. Our custom code also works but cannot figure out where our CO is being called.
    Any suggestions please?
    Thanks,
    Swati.

    Guys,
    Using "About the Page" link on UpdateExpenseAllocationsPG, I found SplitCriteriaTblCO controller class instead of UpdateKffCO class, that was extended to HumUpdateKffCO custom class.
    Our custom code is still intact even though we do not find our custom CO. Probably we have to look elsewhere to find it, no idea!.
    I just need to know how to remove our iExpense extension. In order to remove the iExpense extensions in the instance where the OIE.K was not applied, we just removed the personalization at site level, where the controller HumUpdateKffCO was called and that took care of it.
    --Swati.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • 2 Threads issues. How to return data from a thread located in other class

    I have 2 questions.
    This is the context. From main I start one thread that does a little job then starts another thread and waits for it to end to continue.
    1) The last started thread needs to return a string to the Thread started from main. How can I accomplish that, because I read that I cannot use
    synchronized methods outside different classes (and the threads belongs to different classes).
    2) From the main thread I start the Second Thread located in another class like this ClassName obj = new ClassName(arg); obj.start(); obj.join()
    Is that correct for waiting for the created thread to finish ?

    1) The last started thread needs to return a string to the Thread started from main. How can I accomplish that, because I read that I cannot use
    synchronized methods outside different classes (and the threads belongs to different classes).Threads do not "belong" to classes. Class code executes in a particular thread. The class instances exist as long as something, somewhere, holds a strong reference to them.
    So when you start a new thread, hold a strong reference to the object being executed by that thread. When the thread is done, retrieve your data from that object.
    Even better, don't subclass Thread to create your objects. Instead, implement Callable, and use a ThreadPoolExecutor to execute it.

  • Can not find file must locate each song one at a time need to restore my whole library

    can not find file, must locate each song one at a time need to restore my whole library

    Hello BadSteve,
    It sounds like iTunes seems to have lost track of all your music and you must locate each file individually. I would recommend at this point that you check for 3rd party plugins to see if there are any causing an issue:
    iTunes: Troubleshooting issues with third-party iTunes plug-ins
    http://support.apple.com/kb/ts3430
    If the issue persists after removing the plugins, I would next try recreating your iTunes library:
    iTunes: How to re-create your iTunes library and playlists
    http://support.apple.com/kb/ht1451
    Thank you for using Apple Support Communities.
    Regards,
    Sterling

  • Why does my ipod touch no longer find my correct location?

    Up until a couple of months ago, no problem - when at home my touch found my exact location on Long Island. But for the last two months, it thinks I'm in Maryland. My wife has an ipad. Using the same wifi network it finds the correct location. I've tried resetting the touch, but it keeps telling me I'm in Maryland, not New York. Any ideas as to why this happened, or how I can correct it?

    If you've tried resetting it and that hasn't helped, then you may have to submit your wifi to Skyhook database. The only other thing is if you've recently moved I would [read this|http://www.technipages.com/ipod-touch-how-to-change-current-location.html] , otherwise you can go [here to submit your wifi to the Skyhook database|http://www.skyhookwireless.com/howitworks/submit_ap.php].
    Hope that helps.

  • I just noticed that I can no longer select photos out of my finder that are located in my Aperture/Iphoto Library.  I used to be able to attach photos to my gmail out of the aperture library in the finder and for some reason, no longer can.

    I just noticed that I can no longer select photos out of my finder that are located in my Aperture/Iphoto Library.  I used to be able to attach photos to my gmail out of the aperture library in the finder and for some reason, no longer can.
    I can't access these images except to go into the applications. 
    Also, I'd like to import my iphoto library into aperture, and move aperture library to an external drive.  I tried the import first, but there wasn't enough space.  Then I tried copying over the aperture library onto the external drive but it failed bc it said file was in use. 
    As it is, I only have 50gb left on my imac, and the aperture library is 150gb.  Also, I have over 10k images in both libraries combined and there are tons of duplicates that need to be sorted, and hopefully not messed up because I've organized most of them.
    So in short, I need to know how to do the following:
    -select photos in finder in aperture/iphoto libraries
    -move aperture library to live on external drive
    -import iphoto library into aperture library
    -eliminate dups but maintain organization
    -moving forward i need a better workflow so that I import images from camera, and can organize right away into albums rather than creating projects by default and then creating albums so essentially the photos are in 2 different places, even tho they are referenced
    -live happily ever after
    Thanks in advance for any support you can offer!!

    If you're using apps like iPhoto or Aperture then they replace the Finder for managing your photos. The point is that you use the (many) options available via these apps for the things you want and need to do with the Photos.
    So, simply, you don't select the photos in the Finder. I'll append the supported ways to do this - which are faster and will yield the current version of your Photos - to the end of this post.
    -move aperture library to live on external drive
    Managed or Referenced Library? Managed -
    Make sure the drive is formatted Mac OS Extended (Journaled)
    1. Quit Aperture
    2. Copy the Library from your Pictures Folder to the External Disk.
    3. Hold down the option (or alt) key while launching Aperture. From the resulting menu select 'Choose Library' and navigate to the new location. From that point on this will be the default location of your library.
    4. Test the library and when you're sure all is well, trash the one on your internal HD to free up space.
    Referenced -  relocate your Masters first.
    These issues are covered in the Manual and on this forum hundreds of times.
    -import iphoto library into aperture library
    FIle -> Import -> iPhoto Library? Have you done this already? If so are you trying to move the Masters to Aperture from an  iPhoto Library? Or Consolidate them?
    -moving forward i need a better workflow so that I import images from camera, and can organize right away into albums rather than creating projects by default and then creating albums so essentially the photos are in 2 different places, even tho they are referenced
    You can't. Every photo is in a Project.  They’re the basic building blocks of the Library.
    You might want to spend a little time with the manual or the video tutorials. I'm not sure you've grasped the app  you've purchased.
    The following is written for iPhoto, but about 97% works for Aperture too.
    There are many, many ways to access your files in iPhoto/ APerture:   You can use any Open / Attach / Browse dialogue. On the left there's a Media heading, your pics can be accessed there. Command-Click for selecting multiple pics. This is what you use to attach your shot to your GMail
    (Note the above illustration is not a Finder Window. It's the dialogue you get when you go File -> Open)
    You can access the Library from the New Message Window in Mail:
    There's a similar option in Outlook and many, many other apps.  If you use Apple's Mail, Entourage, AOL or Eudora you can email from within iPhoto/ Aperture.
    If you use a Cocoa-based Browser such as Safari, you can drag the pics from the iPhoto Window to the Attach window in the browser.
    If you want to access the files with iPhoto/ Aperture not running:
    For users of 10.6 and later:  You can download a free Services component from MacOSXAutomation  which will give you access to the Library from your Services Menu.
    Using the Services Preference Pane you can even create a keyboard shortcut for it.
    or use this free utility Karelia iMedia Browser

  • How to find out the tables related to CRM datasources?

    How to find out the tables related to CRM datasources? For example, the table related to 0CRM_OPPT_H.
    Regards,
    R.Ravi

    Hi Ravi,
    To find out all tables used go into the CRM source system to transaction RSA3 and prepare the selections for extraction of your datasource.
    In a parallel session execute transaction ST05 and press the button 'Activate Trace'
    Go back to the extracor checker and execute the extraction.
    Switch sessions and subsequently 'Deactivate Trace' and 'Display Trace'.
    This will list all tables used.
    regards,
    Olav

  • Where and how to find the storage locatation for the consignment stock

    where and how to find the storage locatation for the consignment stock (customer stock )  for more than one storage location .
    table :msku
    material no    -   werks - batch
    xxx                   sg11  - 200352ac
    table : mchb
    material no    -   werks  -lgort - batch
    xxx                   sg11   sg10   200352ac
    xxx                   sg11   gs11   200352ac
    note : each stock location having same batch no in different storage and my question how to find which link for msku to mchb .

    Hi,
    Try the table MARD: Storage Location Data for Material, where in the field LABST will give the stock field, against a given material/plant/Storage Loc.
    Regards,
    JLN

  • Cannot compile Library project in Flash builder 4: Unable to locate specified base class

    I am migrating from Flex builder 3 to Flash builder 4, during that process I found that Flash builder could'nt compile Flex Library projects which contains components in the form of mxml files. Compiler throws "Unable to locate specified base class".
    I have narrowed it down to by creating a flex library project named test library, below its screenshot with its package structure
    ControlA is based on componentA
    when i compile this project, mxml compiler throws this error
    Unable to locate specified base class 'components.componentA' for component class 'ControlA'.
    I cannot upload project code because file uploads are disabled on this forum so I am going to paste the code for both componentA and controlA
    componentA
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:local="*" width="400" height="300">
    </mx:Canvas>
    ControlA
    <?xml version="1.0" encoding="utf-8"?>
    <components:componentA xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:components="components.*" width="400" height="300">
    </components:componentA>
    To further test it, I have made another library project with same package structure using pure AS3, and it compiled without errors

    It might be this happens and other errors if you forget to Run Flash Builder 4.5 Buritto and startup the other version FB4.
    It uses the same project listings and that can be confusing since you're not expecting the old version to be aware of new Buritto (MobileApplications) projects you added (thinking) only to the BETA version installed elseware no doubt.
    Well it might not be your problem but worthy of noting for other's I'm sure.
    Otherwise you've double checked you're using SDK 4.5 Hero with it too! right?

Maybe you are looking for

  • I can no longer turn on or off 32 bit to 64 from the info window.

    I can no longer turn on or off 32 bit to 64 from the info window. I have done a total reinstall with system 10.6 and Logic with no results. I was running Lion but it would allow me to run my Tascam FW-1884. I need to switch back to 32bit on Logic to

  • Automatic Payment Program Issues

    <h4>I have been trying to do the configuration for automatic payment and I keep getting this same error after the payment proposal is run. The payment proposal is created but all the invoices are put on the exception list. To help with the diagnosis

  • Manual tabular form and query based LOV

    Happy new year everyone! Okay so, I've run into an error when making one of the fields in a tabular form into a select list. report error: ORA-20001: Error fetching column value: ORA-06502: PL/SQL: numeric or value error: character string buffer too

  • The size of folders increase automatically bcause of which I'm unable to work on iPhone 5

    The size of folders increase automatically bcause of which I'm unable to work on iPhone 5.

  • Want to embed 3D models into pdf

    I Want to embed 3D models into pdf created from autocad or teamcenter or unigraphics. I have acrobat professional, what else or how do i do that. Please help me ASAP, its very urgent.