Getting exe path - JSmoothed my jar

I created an application and I read the path of my jar code like this:
Class cls =myClass.class;
        ProtectionDomain domain = cls.getProtectionDomain();
        CodeSource source = domain.getCodeSource();
        URL url = source.getLocation();
        String path=url.toString();
        path=path.substring(0,path.lastIndexOf('/'));Let�s suppose my app.jar is located in "C:/Program and Files/mySoftware/bb.jar"
Then, my path returns "C:/Program and Files/mySoftware"
Now I wrapped my jar into .exe file using Jsmooth(yes, I need to do that)
When I run my .exe file it finds a different code location like this:
"C:/Program and Files/tmp/images".
Is there a different way of grabbing the exe path?
Thx!!

ThomYork wrote:
Hi again DrLaszlo.
I tried all the previous answers on the thread about the path.
Now that I created a file .exe for my application, I could get its path using
String tmp = System.getProperty("user.dir");
Actually that's how you get the current working directory. Probably you set that to be the directory where the exe was located, but you can't rely on that in general.
Since I was trying to load an image file I had the MalformedURLException when I created
the url using the path.
So, I verify if "tmp" starts with "file:\". If not, I add it and works fine.
if(!tmp.startsWith("file:\\")){
     tmp="file:\\"+tmp;     
You should use slashes in URLs, not backslashes.

Similar Messages

  • Getting absolute path of a JAR from its classfiles?

    I am creating a class witch is going into a jar-file. With this jar-file I will also have another file (config/data-file). That file will allways be in the same directory as the jar-file.
    What I am wondering is: How can i programatically get the path of the "current" JAR file the "current" class is contained within, so that I can open/read the config/data file?
    Today I use a method which i hope I can replace with a better method:
    private static String jarfile="progconf.jar";
    private static String projectname="ProgramConfig";
    public static String getJarPath() throws Exception{
         try{
              String jvc = System.getProperty("java.class.path")+";";
              if(jvc.indexOf("\\"+jarfile+";")>0){
                   jvc = jvc.substring(0,jvc.indexOf("\\"+jarfile+";"))+"\\";
                   jvc = jvc.substring(jvc.lastIndexOf(":")-1); //Filsti
              }else if(jvc.indexOf("\\"+projectname+";")>0){
                   jvc = jvc.substring(0,jvc.indexOf("\\"+projectname+";"))+"\\";
                   jvc = jvc.substring(jvc.lastIndexOf(":")-1); //Filsti
              }else{
                   throw new Exception("Klarte ikke finne JarPath!");
              return jvc;
         }catch(Exception ex){
              throw new Exception("getJarPath-" + ex.getMessage());
    }-Wolflad

    check out my replies at the link shown below:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=494736
    ;o)
    V.V.

  • 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 acrobat reader exe path on user system at runtime

    aoa!
    i want to open oracle reports in acrobat reader. for this purpose, i need acrobat reader exe file path of client. plz help to get that path in oracle reports.
    Tools used:
    Oracle Reports version 6
    Database: 10 g
    OS: Windows XP SP2
    Regards
    M. Asim Hameed

    <userSettings>
            <Client.Properties.Settings>
                <setting name="ParamValue" serializeAs="String">
                    <value>OFF</value>
                </setting>
            </Client.Properties.Settings>
        </userSettings>
    If i modify the value during runtime from "OFF" to "ON" by opening the
    Client.exe.config, the application still access the old value. But if i close the application and open again then it reads the updated value.
    Is there someway to make the exe read the updated user settings at runtime .
    Regards Nithin Joseph
    Hello,
    I am afraid that it is impossible because the application just read that value just one time when loading the application, and the modification will not affect the value any more.
    Instead, you could place a xml file, and load the value when you want to do any action with the event handler.
    Regards,
    Carl
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Any System Command to get/know the Iexplore.exe path ???

    Hi,
    I want to know, where is the Iexplore.exe file in my system.
    Is there any System command to know the IE .exe path
    like System.getProperty("os.name") ??
    or manually we need to check all files ?
    Thanks for Advance.
    - k seelam

    I think there is no 'system command' provided in Java or Win32 APIs.
    But if you need it, use some of third-party Java class libraries that can handle (read or write) Windows Registry and check some of the related keys that contain informations you want.
    ('HKCR\htmlfile\shell\open\command' key contains the current default html browser for example. You'd better to refer MSDN to find out more.)

  • CLASS-PATH troubles in JARs

    I'm having trouble with my Jar files. I have all the classes associated w/ the project in jar files in a lib directed. I then jar that directory w/ the main class file along with some extra directories (images etc). When I run the jar file created using the -jar switch...it states that it can't find a file that is inside the jar file itself. It will work if I have the directories and the files un-jar'ed in the same directory as the jar however I'm hoping that I dont' have to do that.
    Below is my manifest file:
    Main-Class: btCommander
    Class-Path: lib\namespace.jar lib\relaxngDatatype.jar lib\jaxb-libs.jar lib\jaxb-api.jar lib\jaxb-impl.jar lib\classbox.jar
    (i do have a carriage return after the last jar file in classpath).
    When i jar the files (using either Ant or jar.exe) it packs the files however it doesn't allow me to execute the jar alone.
    Any help will be appreciated.
    Llama

    My main class is in the root of the jar file in question. the only other item in the jar is the lib directory which houses the other jar files. After playing around with the different switches and such I ended up just getting rid of the overall jar and for distribution just went for zip format and then just the file from outside...nothing big...just a bit annoying that's all :) Maybe I'll be able to do this with future versions of the JDK (hopefully).
    Thanks you guys for the suggestions none-the-less.

  • Get current path in Java LINUX?

    Hi,
    I m trying to get the current path of file using the getAbsolutePath.Its works fine (gets the current working directory) in Windows both in debug & release mode.Whereas, in LINUX ,It is not working.
    i.e.,It gets home path instead current path while running in release(by clicking jar file).
    File objfile = new java.io.File("SampleCloud.txt").getAbsoluteFile();
    JOptionPane.showMessageDialog(null, objfile.getAbsolutePath());
    Message box display home path instead of current path on linux.
    I dont know why its so.Ur help would be appreciated.
    System.getProperty("user.dir")
    I used it but its also taking the home dir path on linux
    Sonal
    Edited by: 850979 on 13-Apr-2011 06:04

    Thanks for your reply.
    I have copied the .jar file in a new directory under <user name>/Documents. The SampleRTLCloud.txt is also in the same directory. How do I get the path of the directory where the application is run from?
    Your help will be much appreciated.
    Sonal

  • How to get the path of my java dir in java?

    Hi,
    I want to get dir path in java.
    I want to know from where I'm runing in the computer
    somthing like this?
    String osUserName = System.getenv("????????");
    Thanks and have a good day!

    Hi,
    I have "deploy" directory, and I whant to be able to import it to every computer with out to define things in class path.
    in my deploy I have my jar, lib directory, bech file to run (ther I have script with the libs path..), I want to put in deploy the db.properties file.
    then just ask "from where I'm running" -->
    String osWorkDir = System.getProperty("user.dir");then just to add this path "/db.properties"
    The problem with it:
    osWorkDir = C:\MyJava\deploy
    and I need:
    C:/MyJava/deploy
    Thanks :)
    I want to import my

  • How to get the path of the image stored in DMS

    Hi everyone..
    My question is that I have attached an image with an order through transaction jha2n..
    Now my requirement is to get the image in report..
    I know the Logical id in ISM_l_ord class and physical id in ISM_P_Ord class.
    I know that link between image and order is in SKWG_BREL.
    But i am not able to get the path so that i can show the image in docking control.
    pls help to retrive the path of the image stored...
    Thanks
    Pooja

    EpicMaster wrote:Now the problem is when I run the application through the .jar file in the dist/ directory the images simply wont load...
    ..lblProduct.setIcon(new ImageIcon("Resources.zip/res/Product.png"));
    Now the problem is when I Build&Clean the whole project which creates a /dist directory containing the complied and execulatble .Jar file for the application AND a folder called "lib" which contains the Resource.Zip folderThe String based constructor to ImageIcon presumes the String represents a File path. File objects do not work with resources inside Jar or Zip archives, for those, you need an URL. Gain the URL using something like..
    URL urlToImage = this.getClass().getResource("/res/Product.png");

  • How to get the path of the cache directory ?

    Hi everyone,
    I need to get the path of the cache directory to copy files into it (these files are security files that are necessary to encrypt data).
    Maybe there is a jnlp.jar to have object that implements a method getCachePath() ? But I can't find it.
    Any ideas ?. thanks.

    you can find the cache location by finding the location of the jar file you are running from:
    URL resource =
    this.getClass().getClassLoader().getResource("testResource");
    if (resource != null) {
    String s = resource.toString();
    if (s.startsWith("jar:")) {
    int index = s.indexOf("!");
    if (index > 4) {
    String fileurl = s.substring(4,index);
    if (fileurl.startswith("file:")) {
    String path = fileurl.substring(5);
    // now path is the path to the jar file in the cache containing the resource
    /Dietz

  • Path to rt.jar from C program

    How do I get path to rt.jar from a program written in C.
    Thank you

    Just like anything else you do in C. Pass in in via the command line or use a config file or use an environment variable or parse the registry (OS specific), etc.

  • Get the path of the running java program

    Hi,
    Is it possible to get the path of the main java class that I am running.
    For example if I am running myProgram.class can I get the path of that class from itself.
    Best regards,
    Chamal.

    Hi,
    Is it possible to get the path of the main java class
    that I am running.
    I found this one recently.
    You can get the Codebase as a URL. This will point to the classes directory, or the jar file or the online URL in the case of an applet or the like.
    URL codeBase = getClass().getProtectionDomain().getCodeBase().getLocation();will get you the location from which the class it's called in was loaded. (In a static context use
    Myclass.class.getProtectionDomain().....)

  • ZAM collector failed to get WIF path message

    This irritating message constantly appears in C:\Program Files\Novell\ZENworks\Asset Management\bin\colw32.log on many PC's. On some PC's it appears every time the collector service tries to start but on some it only appears infrequently. I need to know how to troubleshoot this message as many of our workstations are not producing an inventory and it's down to this message.
    I have done some tests today on several PC's all logged on as me. Some work, some don't, so it can't be anything to do with policies and rights to the registry. Using ZAM 7.5 IR16 with latest product updates.
    Thanks
    Lenny

    Originally Posted by lennyd
    I should have added, a previous post suggested adding the line
    Diagnostic=1
    into cps.ini which i have done.
    Diag.Exe and DoRes.DLL already exist in the client directory. This has created and populated a file called CClientEvent20081201.log in the client logs directory. However it contains no useful information at all as to why this "Failed to get WIF path" message appears.
    On the particular PC I am using here, there are 2 .WIF files dated 27th November in the InboxCC directory then nothing since so it did work until last week so why it has stopped working now I have no idea.
    Lenny
    I had the same problem. It turns out the Windows firewall was blocking port 7461. Once port 7461 was opened everything started to work.
    Jim

  • 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.

  • System canot get the path specified

    Folder name for my jdk file is C:\Java\jdk1.6.0_05\ and for my jre files is
    C:\Java\jre1.6.0_05\
    While folder name for HelloWorldApp.java is C:\Java.In Command Prompt,while i give command >>C:\Java>dir i get all the three files >>>
    1.HelloWorldApp.java 2. jdk1.6.0_05 3. jre1.6.0_05
    User Variable value>>C:\Java\jdk1.6.0_05\bin and System Variable value>>
    C:\Java\jdk1.6.0_05\bin
    In Command Prompt, while i give command >>C:\Java\jdk1.6.0_05\bin\javac HelloWorldApp.java, i get error "System cannot get the path specified."
    Can anyone help please?
    damp
    Note: Under Java(TM)SE Development Kit Update 5, i downloaded jdk-6u5-windows-i.586-p-iftw.exe

    As people keep saying: you need to set the operating system's PATH variable.
    Have a read of the [Hello World tutorial|http://java.sun.com/docs/books/tutorial/getStarted/cupojava/win32.html] and the [Common Problems|http://java.sun.com/docs/books/tutorial/getStarted/problems/index.html] page - yours is number one on the list.

Maybe you are looking for