Getting file path where .jar file resides

I'm using a .jar file to run my Java app. Can anyone tell me how to return the directory where the .jar file is being run? Thanks very much.
-Pete

You can get the folder or jar file from which a given class was loaded.
URL source = getClass().getProtectionDomain().getCodeSource().getLocation();
String filePath = source.getFile();

Similar Messages

  • How to find the path where the program resides

    I need to use the path where the running program file resides.
    My purpose is to make a program where some parameters are in a separate file. I want to have it in the same directory as the .jar program is. This way I could start and run the program from a memory stick.
    Is there a way to get the program path?
    Urpo Pietil?
    Edited by: urpo on Feb 12,:12 AM
    Edited by: urpo on Feb 12,:12 AM

    This will tell you the directory that contains the running program:
    System.getProperty("user.dir")

  • Newbie - Dreamweaver CC 2014 - Document Scan - Get Save Path/File

    Hi, 
      I've been a programmer for a long time but have done very little web development. Last time I touched dreamweaver has to be 10 years ago. A company I'm working with is developing a web front end for their system. In their existing system, they are able to scan a document by pressing a button in the application. The button push scans the document and open Acrobat Pro. When the user saves the PDF, they are able to get the path where the user saved the file as well as the file name and then they store that information in the DB of previously mentioned system. From the application they are hitting a TWAIN driver to invoke the scanning (if I understood correctly). The scanner I saw this done with is an EPSON GT-S50 and I believe they are programmatically reading the registry to get the last 15 files that were saved and determining the path and file name from there.
    Since they are now developing a web front end over the existing business logic, there are some things they have asked me to figure out. The first of which is how to duplicate what I mentioned above in a web front end. That being said, here's what I need to do:
    - Add a button labeled "Scan" to a web page with Dreamweaver that will invoke the scan process of the EPSON Scanner.
    - Have that scanned document open in Acrobat.
    - On save of the document in Acrobat, I need to get the path and file.
    - Add a button to view the file labeled "View".
    - On select of the "View button", I need to display the PDF on the same web page.
    I've done a bunch of reading so far and I haven't quite found what I need. If you can help point me in the right direction or have done something similar or even if you just want to offer moral support (haha) please let me know. I'll respond as quickly as possible to additional questions, I need to move on this...
    Thanks,
    Rob

    Hi Nancy,
    Thank you for responding. I guess the environment would be helpful.. (Sorry) . The web front in will be on servers in one of the major clouds (AWS/Rackspace/etc) and the DB's will be on other servers in the cloud while the servers will be at the customer's offices. So yeah, it is complicated. What I'm trying to come up with is  way to do it without tying the end customer to have to marry their network to the cloud network or forcing them to use RDP or Citrix etc.. Trying to come up with the most flexible option. One other thing they are shooting for is mobile compatibility. I just started working on this with them, I wasn't involved in the meetings along the way...
    Thanks,
    Rob

  • How can i get the path to config folder placed inside the jar file?

    Hi i have developed an RCP application using eclipse.
    In my application config directory is there.
    When i export my RCP application as JNLP Project the jar file is created which contains config folder inside it.
    When i download the application using java web start , how can i get the path to config folder placed inside the jar file?
    Will the config folder exists in local cache in my system?
    Help needed.
    -Deepak

    -- This works in CS6:
    tell application "Adobe InDesign CS6"
      set myDocument to active document
      set selectedRectangles to selection of myDocument
      set theGraphicsLink to file path of item link of (graphic 1 of (item 1 of selectedRectangles))
    --> "Macintosh HD:folder/folder/filename.tif"
    end tell

  • How to get path of jar file

    I am using a class which is present in a jar file.
    There are lot of versions of this jar file are present on machine.
    I am accessing one class from this jar.
    How do I know which jar is used by application.
    How to get the path(path on machine like c:\java\lib) of this jar file.

    URL jarURL = this.getClass().getResource("/whatever.class");will return you a jar:// URL. Experiment with that. (Remember that "whatever.class" needs to be prefixed by the full name of the package the class is in.)

  • Terminal Command, how to set defaults write, make application(s) use directory path where file last saved?

    Does anyone know whether there's a terminal command to make all applications remember/use the last directory/path where I last saved a file?
    For example, let's say there are (10) ten PDF's on a website, and I want to use Preview.app to open and save each file to the same directory.
    Problem is, after each time I save a file, Preview.app doesn't automatically remember/use the last directory where I saved my file(s).
    Forcing me to navigate back to the same directory after each time I save a file; super-annoying.
    But, for some reason, when saving images from the web, Firefox remembers the last directory where I saved the file (jpeg).
    So I'm hoping there's some way, possibly a terminal command to set/force all applications (including Preview.app) to remember/use the directory/path where file(s) were last-saved.
    Anyone?

    Get the third-party utility Default Folder X 4.4.9.

  • Change the path where i want to store the file

    i want to get the name of the Directory Is there any FM to get it.
    Means i have a scenario that I am trying to download a file from Application
    server and i am trying to Download where ever i want to store..... So It has
    to open a save Dialog box But by default the name of the file should same as
    that of the application server filename. But i should be able to change the
    Path where i want to store. Can any one help me out in this issue.

    Hi,
    Please check this.
    DATA: DIR TYPE STRING.
    CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_BROWSE
      EXPORTING
        WINDOW_TITLE         = 'Select Folder'
        INITIAL_FOLDER       = 'C:'
      CHANGING
        SELECTED_FOLDER      = DIR
      EXCEPTIONS
        CNTL_ERROR           = 1
        ERROR_NO_GUI         = 2
        NOT_SUPPORTED_BY_GUI = 3
        others               = 4.
    Now that you have the directory, you can add the filename and save to the location.
    Regards,
    Ferry Lianto

  • Problems creating file. Can't get resource path.

    Hey, I'm new to Java with an Actionscript background and I'm using NetBeans IDE.
    Now this comes with my basic lack of understanding for how Java works but I'm getting confused a lot so if someone could just steer me in the right direction I'd be very grateful.
    Essentially I'm checking for a config file and if it's not there, I want to create a default one but the paths are messing me up. class.getResource seems to use the src or the build/classes dir? What's the relationship of these? If I put assets in the src folder should they be moved to the build folder or something like that?
    The actual problem in code is that if I create a file, (config.xml) and put it in my src folder I can grab it using Main.class.getResource("config.xml"); Which is great but if the file's not there it throws an exception..
    Now In actionscript I'd use the File class, which seems very similar to Java's. I'd pass in a literal for the filename "config.xml" and prepend a constant that gives the path of the apps storage directory. If the file's not there then the File.exists property == false.
    What I need is to get the same path that getReresource("config.xml") outputs, but in a File and I can't do that with the exception being thrown because the file's not there.
    Any help appreciated.. I can't read another blog full of different setups or face another Google page of results pertaining to different problems.
    - Chris W

    RoninStretch wrote:
    Essentially I'm checking for a config file and if it's not there, I want to create a default one but the paths are messing me up. class.getResource seems to use the src or the build/classes dir?It looks relative to the classpath, as I recall.
    What's the relationship of these? If I put assets in the src folder should they be moved to the build folder or something like that?NetBeans might do that for you. It's a reasonable thing for a build system to do.
    You might be better off working without an IDE until you're more familiar with Java.
    The actual problem in code is that if I create a file, (config.xml) and put it in my src folder I can grab it using Main.class.getResource("config.xml"); Which is great but if the file's not there it throws an exception..Actually I think getResource will return null if the resource isn't there. Are you not checking for null?
    Now In actionscript I'd use the File class, which seems very similar to Java's. I'd pass in a literal for the filename "config.xml" and prepend a constant that gives the path of the apps storage directory. If the file's not there then the File.exists property == false.The Java File object refers to a path on the filesystem, not a virtual one in the manner of Class.getResource. Check the result of getResource to see if it's null.
    What I need is to get the same path that getReresource("config.xml") outputs, but in a File and I can't do that with the exception being thrown because the file's not there.Can you show us the actual exception and actual code?
    Anyway, if you're packaging all this up in a jar, you wouldn't put the new config.xml that you create in the jar anyway.
    More likely you'd do something like:
    1) check user's home directory for config.xml
    2) if it's not present, check to see if there's a config.xml packaged in your jar.
    3) if the user has any config changes, put them in a config.xml in the user's home directory.
    So you wouldn't be trying to get the path of the default config.xml anyway.
    Or maybe you can use the Preferences framework.

  • How does the communication will happened between SOA-Composer(where DVM file resides) and EM console (Where composite resides)?

    How does the communication will happened between SOA-Composer(where DVM file resides) and EM console (Where composite resides)?
    And also i would like to how A business rule(Which will be resides in SOA_COMPOSER) will be communicated to Soa Composite(Resides in EM Console)?

    whenever you deploy a new composite it gets stored in the MDS data
    store, i.e. the metadata service and not the dehydration store (the
    SOAINFRA database).
    Composer works directly with the MDS schema.
    EM reads the same schema (MDS) to see what composite are deployed on the
    partitions.
    All runtime instance data is stored in the SOAINFRA database.
    Hope this helps,
    Anatoli

  • Get installation path of web application from class file

    Can anybody tell me how I can get the path on disk to the root of my web application from a class file. Im running under Tomcat 5.5 and I have 3 copies of the same webapp under 3 differenet directories:
    C:\xxx\dev\yyy
    C:\xxx\test\yyy
    C:\xxx\prod\yyy
    Based on which directory the web-app, I need to do a lookup on a properties file to pull the right jdbc connection to connect to the appropriate database. So it would be similar to using getServletContext().getRealPath("/") from a .jsp file.
    Thanks,
    Jason

    Sorry for not clarifying. I have a properties file with name/value pairs. I know where this properties file is and I can do a lookup in it. In this file, I have jdbc connection names which point to corresponding jdbc resources in my context.xml file.
    jdbcDevDatabase=jdbc/tfmDev
    jdbcTestDatabase=jdbc/tfmTest
    jdbcProdDatabase=jdbc/tfmProd
    These connections are for dev, test and prod databases. Now based on where the web-app is installed on disk, i.e-dev dir, test dir, prod dir, I want to retrieve the corresponding connection. The problem is I don't know how to get a handle to the web apps real path on disk without access to the request object or using getServletContext().getRealPath("/") which are not available to me in a class file.
    Thanks,
    Jason

  • Help in getting swingx-ws-2007_10_14.jar file

    I have to build a desktop application where I need this jar file. I am continuously trying to get the swingx-ws.jar file in the net, but till now I have not found that. The website swinglabs.org is also down for a while. Can u tell me where I might get that. the date for this jar may be different also.

    I have to build a desktop application where I need this jar file. I am continuously trying to get the swingx-ws.jar file in the net, but till now I have not found that. The website swinglabs.org is also down for a while. Can u tell me where I might get that. the date for this jar may be different also.

  • Get the directory where application files exist.....

    Hi ,
    How to get the directory where application files exist....????
    I have found a way....such as:
    Right - click on the application name ... on the pop-up menu... select "Add to <application_name>" and then on the window appeared... i get the dir on the title of this window....
    Is there any simpler method to obtain the dir...????
    NOTE: I use JDev 10.1.3. on windows XP platform...
    Many thanks ,
    Simon

    hi Simon
    If you not only want to see the path, but also want to copy-and-paste it, you can use the "Edit > Copy Path" (Ctrl+Shift-C) menu item.
    success
    Jan Vervecken

  • Where ( in my desktop system ) RMS files reside usingNokia_S40_SDK_6230i

    hi
    I am using WTK 2.0, I want to know where ( in my desktop system ) RMS files reside i am working on Nokia_S40_DP20_SDK_6230i, when testing my application using this Emulator.
    However, when i use "DefaultColorPhone" the RMS files go to the folder " C:\WTK22\appdb ".
    plz reply soon.

    This is for UI40 7210...
    C:\WTK2.0\wtklib\devices\Nokia_7210_MIDP_SDK_v1_0\bin\jam-apps\xyz.jar\RMSfile

  • File dialog box: how get full path and filename (firefox 3.0 problem)

    Hi,
    I have a smilar problem then discussed in this thread: file dialog box: how get  full path and filename
    Now this solution doesn't seem to work in firefox 3.0,I only get the filename but not the full path.
    I have tried to solve this problem by adding *"netscape.security.PrivilegeManager.enablePrivilege("UniversalFileRead");"* in a javacript function but that doesn't do the trick
    Although when i tested it local it does work.
    Any idees how to solve this?
    Best Regards
    Stijn

    Actually, that is strange and scarry. With 20% of the browser market share they decide to behave like Microsoft did in the past - they want to decide what users need and what they do not need. With 3.0 I have a real problem with some of my applications. They are all tested in IE6, IE7, FF2.0 and they all work the same way (they even work with Opera and Safari). Now, I will for sure not go there and make it work for 3.0, just because 2 out of 200 users use FF3.0. Up to now I have always recomended FF as the best browser. 3.0 causes my opinion to change completely. Competition is always good but it is a question if it is good if we have 20 different browsers out there with equal market shares.
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.opal-consulting.de/training
    http://apex.oracle.com/pls/otn/f?p=31517:1
    -------------------------------------------------------------------

  • Error in reciever file adapter , where i am getting file name dynamically

    hi all,
    error in reciever file adapter , where i am getting file name dynamically, please help me in this isssue , i am trying for a long time
    MP: Exception caught with cause com.sap.aii.af.ra.ms.api.RecoverableException: Exception in XML Parser (format problem?):'java.lang.Exception: Message processing failed in XML parser: 'Conversion configuration error: Unknown structure 'ns0:MT_eINVOICE_RECV' found in document', probably configuration error in file adapter (XML parser error)': java.lang.Exception: Exception in XML Parser (format problem?):'java.lang.Exception: Message processing failed in XML parser: 'Conversion configuration error: Unknown structure 'ns0:MT_eINVOICE_RECV' found in document', probably configuration error in file adapter (XML parser error)'

    i am getting new error
    MP: Exception caught with cause com.sap.aii.af.ra.ms.api.RecoverableException: Channel has not been correctly initialized and cannot process messages
    this is my strcuture
    and i have changed my structure
    <HEADER>
    <ADDRESS1/>
    <ADDRESS2/>
    <ADDRESS3/>
    <ADDRESS4/>
    </HEADER>
    <HEADER_GST>
    <TAX1/>
    <TAX2/>
    <TAX3/>
    </HEADER_GST>
    <LINE>
    <QTY/>
    <UOM/>
    <UNIT_AMT/>
    <CHARGE_TO_DT/>
    </LINE>
    <FILENAME>
         <FILENAME/>
    </FILENAME>
    i have given the recordset structure as
    HEADER,HEADER_GST,LINE,FILE

Maybe you are looking for

  • Acrobat Pro won't open a PDF file.

    I know this isn't a Mac question but I've been to Adobe and they are no help. I have PDF files that were created by Acrobat Pro that will not open when I click on the file icon yet, if I open the Acrobat program it will open the file. This is annoyin

  • How can I just email a photo without a set up and text and all that stuff?

    I used to be able to select a photo and email it - no and for quite a while a whole set up appears with place for text and choices of design, etc. Can I no longer just send plain unadorned photo?    I have a MBP 2010 running Lion. Thanks.

  • Saving a .rgb (SGI format) file in Extendscript

    Hello everyone,     I'm writing a script in javascript that saves out some .rgb files.  I tried using the script listener by selecting Save As in Photoshop. However, the resulting script would only save .sgi files: var idsave = charIDToTypeID( "save"

  • Debit / Credit Indicator in RBKP table

    Is anybody aware of a field within table RBKP that shows whether the invoice was a debit or credit? I've got an idea there are fields in other tables that use a single letter (H, C, S?) or a two digit number (30, 40 ?) to indicate a debit or credit b

  • Confused about Volumes

    Using GrandPerspective to visually assess the file sizes on my main drive, an internal Seagate 320, it shows duplicate listings for my user folder: Users/chuckbryant/(then Desktop, Downloads, Library, etc) AND Volumes/Chuck MBP/Users/chuckbryant/(Des