How to get the application path?

Does some body know how to get the application path in Java? Here is an example about what I'm thinking: Let's imagin the application is on "c:\try" or "c:\ProgramFiles\MyApp". My question is how can I find the path where the application is. Please give an example if you know the answer. Thank you so much.

Those two replies give you some useful directories, it's true, but maybe not what the OP asked. However the OP asked for something that doesn't have a meaning (applications don't have to be "on" any directory, whatever that might mean).
Would the OP like to describe what the actual problem is here?

Similar Messages

  • How to get the current path of my application in java ?

    how to get the current path of my application in java ?
    thanks

    To get the path where your application has been installed you have to do the following:
    have a class called "what_ever" in the folder.
    then you do a litte:
    String path=
    what_ever.class.getRessource("what_ever.class").toString()
    That get you a string like:
    file:/C:/Program Files/Cool_program/what_ever.class
    Then you process the result a little to remove anything you don't want:
    path=path.substring(path.indexOf('/')+1),path.lastIndexOf('/'))
    //Might be a little error here but you should find out //quickly if it's the case
    And here you go, you have a nice
    C:/Program Files/Cool_program
    which is the path to your application.
    Hooray

  • How to get the ablolute path of the web application in WebSphere?

    How to get the ablolute path of the web application in WebSphere?
    For example:
    I have installed IBM WebSphere on D:\WebSphere\Appserver, and I created a new appliction named "myapp" on D:\myapp,. How can I get the absolute path of application "myapp"? In other words,how can I get the absolute path of the application's
    root directory?

    In the WebSphere(default), what directory is the Java Bean's root directory ?

  • How to get the absolute path of logicalhost server domain on Windows Sun

    i am reading a file from Xsql Folder, that is located in the logicalhost Sun\AppServer\domains\domain1\applications\j2ee-apps.(IN Sun Application Server)
    I am pretty sure that using the absolute path will solve this issue, so my first question is: How to get the absolute path of logicalhost server domain on Windows?
    i tried with System.getProperty("com.sun.aas.instanceRoot").
    but i am able to retrive Sun\AppServer\domains\domain1 upto this .i am unable to retrive Sun\AppServer\domains\domain1\applications\j2ee-apps.
    please suggest me how u can get absolute path in sun application server

    Take a look here

  • How to get the absolute path of logicalhost server domain on Windows?

    My logicalhost server domain behaves strangely. I am reading a file from collaboration definiton, that is located in the logicalhost/is/domains/domain1/config folder. I thought, that this folder is used as an application root folder so I can read files like ./file from there. And it worked.
    But then I've installed the domain as a Windows service, restarted the PC. When the domain1 gets started, I get exceptions saying that the file can't be found. Then I restart the domain (in domainmgr.bat) and it works again.
    I am pretty sure that using the absolute path will solve this issue, so my first question is: How to get the absolute path of logicalhost server domain on Windows?
    And my second question is: Why does this happen?

    The default folder for a Windows Service is the system32 folder contrary to the instance root folder when starting it as a normal process.
    That's the why, haven't tried the how, but you should be able to get the value by calling System.getProperty("com.sun.aas.instanceRoot").
    Hope this helps
    Paul

  • How to get the full path instead of just the file name, in �FileChooser� ?

    In the FileChooserDemo example :
    In the statement : log.append("Saving: " + file.getName() + "." + newline);
    �file.getName()� returns the �file name�.
    My question is : How to get the full path instead of just the file name,
    e.g. C:/xdirectory/ydirectory/abc.gif instead of just abc.gif
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.filechooser.*;
    public class FileChooserDemo extends JFrame {
    static private final String newline = "\n";
    public FileChooserDemo() {
    super("FileChooserDemo");
    //Create the log first, because the action listeners
    //need to refer to it.
    final JTextArea log = new JTextArea(5,20);
    log.setMargin(new Insets(5,5,5,5));
    log.setEditable(false);
    JScrollPane logScrollPane = new JScrollPane(log);
    //Create a file chooser
    final JFileChooser fc = new JFileChooser();
    //Create the open button
    ImageIcon openIcon = new ImageIcon("images/open.gif");
    JButton openButton = new JButton("Open a File...", openIcon);
    openButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    int returnVal = fc.showOpenDialog(FileChooserDemo.this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
    File file = fc.getSelectedFile();
    //this is where a real application would open the file.
    log.append("Opening: " + file.getName() + "." + newline);
    } else {
    log.append("Open command cancelled by user." + newline);
    //Create the save button
    ImageIcon saveIcon = new ImageIcon("images/save.gif");
    JButton saveButton = new JButton("Save a File...", saveIcon);
    saveButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    int returnVal = fc.showSaveDialog(FileChooserDemo.this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
    File file = fc.getSelectedFile();
    //this is where a real application would save the file.
    log.append("Saving: " + file.getName() + "." + newline);
    } else {
    log.append("Save command cancelled by user." + newline);
    //For layout purposes, put the buttons in a separate panel
    JPanel buttonPanel = new JPanel();
    buttonPanel.add(openButton);
    buttonPanel.add(saveButton);
    //Explicitly set the focus sequence.
    openButton.setNextFocusableComponent(saveButton);
    saveButton.setNextFocusableComponent(openButton);
    //Add the buttons and the log to the frame
    Container contentPane = getContentPane();
    contentPane.add(buttonPanel, BorderLayout.NORTH);
    contentPane.add(logScrollPane, BorderLayout.CENTER);
    public static void main(String[] args) {
    JFrame frame = new FileChooserDemo();
    frame.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    frame.pack();
    frame.setVisible(true);

    simply use file.getPath()
    That should do it!Thank you !
    It takes care of the problem !!

  • How to get the absolute path of a file from the local disk given the file n

    how to get the absolute path of a file from the local disk given the file name

    // will look for the file at the current working directory
    // this is wherever you start the Java application (cound be C: and your
    // application is located in C:/myapp, but the working dir is C:/
    File file = new File("README.txt"); 
    if (file != null && file.exists())
        String absolutePath = file.getAbsolutePath();

  • How to get the document path of the pictures uploaded for products?

    Hi Gurus,
    How to get the document path of the pictures uploaded for products uploaded through tcode COMMPR01?
    Many Thanks,
    Neeraj

    client path.
    I need to get the client path in order to download files form server to client.
    Best regards,
    Huy.

  • How to get the project path ?

    In my servlet, how do I get the project path ?
    I have the following dir structure :
    Web_App
      + build
        lib
      + nbproject
      + src
        test
      + web ( index.jsp , my.jsp , my.html )
        + Dir_Docs ( my file : ABC.txt ) My Servlet is :
    public class My_Servlet extends HttpServlet
      public void init(ServletConfig config) throws ServletException
        super.init(config);
      public void destroy() { }
      protected void processRequest(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
        response.setContentType("text/html");
        PrintWriter out=response.getWriter();
        out.println(System.getProperty("user.dir"));   
    }What I got was : C:/apache-tomcat-6.0.14/bin/
    How to get the project path ? Which is : C:/Web_App/ ?

    Yes, config.getServletContext().getRealPath("index.jsp"); got the job done !
    Thanks.

  • How to get the Application perform actions when exits?

    How to get the Application perform actions when user clicks on the "X" icon in the top right hand corner?
    OR
    If i placed an Exit Button.... when actions that i need to use to allow my application to perform a certain action when it exits?
    Thanks

    frame.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        // do your stuff here
    });The WindowListener and WindowEvent can be found in java.awt.event package
    //David

  • HT4623 i have iOS 4.2.1 in 3G old one. how to get the applications for this iOS

    i have iOS 4.2.1 in 3G old one. how to get the applications for this iOS

    look at this thread
    https://discussions.apple.com/message/22837309#22837309

  • How to get the file path in adf application

    hii all,
    i have a txt file that i am using in my adf application,
    i am passing this txt file through a File Reader, for which i have to mention the file path.
    The file is in web-content and when i am hard coding the complete file path i.e C:/JDeveloper/myApp/ViewController/public_html/log.txt
    the application is working fine when run on integrated weblogic server.
    My requirement is to access this file without giving the static file path, as in case i have to use this application on any other machine..
    for that how to mention the file path-
    i tried using FacesContext to get the context path :-
    FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath();
    which gives me
    \myApp-ViewController-context-root
    after appending public_html\log.txt
    I am using the following path to access the file :-
    \myApp-ViewController-context-root\public_html\log.txt
    again i am getting the java.io.FileNotFoundException
    Does anyone know how to use file from inside the web-content without giving the complete path..???
    Thanks

    Hi,
    If you put your file under public_html folder, you can use this code to access the file:
    For example file is : log.txt
    FacesContext.getCurrentInstance().getExternalContext().getRealPath('/log.txt').toString().trim();
    Thanks.
    - LSR

  • How to get the current path/directory

    Hey,
    I was wondering how to figure out the current path or directory where my Application is running (stored) in! I know there is a statement like getCodebase() for Applets to get the actual path, but I couldn't find anything similar for regular Applications. I think I can not just use a absolute path, since it might run on different os with different file seperator (like /root or c:\). Any help is welcome!
    Thank you very much,
    Marc

    Try this ...
            System.out.println("current directory = " + System.getProperty("user.dir"));
    [/code}                                                                                                                                                                                                                               

  • How to get the pull path name from a file upload window

    Hello everyone!
    I have encountered the following problem with the following JSP code:
    <form method="post" action="filename.jsp">
    Upload JAVA program:
    <input type=file size=20 name="fname" accept="java">
    <input type=submit value="go">
    </form>
    <%
    String s = "";
    if (request.getParameter("fname") != null)
    s = request.getParameter("fname")
    %>
    The value of s is alway the filename. However I want to get the full path in addition to the filename, so that I can read the file. Does anyone know how to get the pull name of the file?
    thanks a lot in advance,

    Dear Sir,
    thanks a lot for your reply. Please let me explain what I intended to do: I want to upload a file from the local machine and then read the content of the file. Therefore I need to the fullpath of the filename like /var/local/file.java instead of file.java. The latter is what I got.
    The problem I have with your code is that the function like "request.getServerScheme()" is not recognized. Maybe is it because I didn't install servelet package? I only installed javax package btw. Also my application runns on Tomcat server if this could give you some information. The error message I had is as follows:
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: 36 in the jsp file: /addExercise.jsp
    Generated servlet error:
    [javac] Compiling 1 source file
    /usr/local/jakarta-tomcat-5.0.12/work/Catalina/localhost/tutor/org/apache/jsp/addExercise_jsp.java:133: cannot resolve symbol
    symbol : method getServerScheme ()
    location: interface javax.servlet.http.HttpServletRequest
    url = request.getServerScheme()
    ^
    An error occurred at line: 36 in the jsp file: /addExercise.jsp
    Generated servlet error:
    /usr/local/jakarta-tomcat-5.0.12/work/Catalina/localhost/tutor/org/apache/jsp/addExercise_jsp.java:136: cannot resolve symbol
    symbol : method getServerScheme ()
    location: interface javax.servlet.http.HttpServletRequest
    + ((("http".equals(request.getServerScheme()) && request.getServerPort() != 80)
    ^
    An error occurred at line: 36 in the jsp file: /addExercise.jsp
    Generated servlet error:
    /usr/local/jakarta-tomcat-5.0.12/work/Catalina/localhost/tutor/org/apache/jsp/addExercise_jsp.java:137: cannot resolve symbol
    symbol : method getServerScheme ()
    location: interface javax.servlet.http.HttpServletRequest
    ||("https".equals(request.getServerScheme()) && request.getServerPort() != 443))
    ^
    An error occurred at line: 36 in the jsp file: /addExercise.jsp
    Generated servlet error:
    /usr/local/jakarta-tomcat-5.0.12/work/Catalina/localhost/tutor/org/apache/jsp/addExercise_jsp.java:139: cannot resolve symbol
    symbol : method getServletConfig ()
    location: interface javax.servlet.http.HttpServletRequest
    + "/" + request.getServletConfig().getServletName()
    ^
    An error occurred at line: 36 in the jsp file: /addExercise.jsp
    Generated servlet error:
    /usr/local/jakarta-tomcat-5.0.12/work/Catalina/localhost/tutor/org/apache/jsp/addExercise_jsp.java:140: cannot resolve symbol
    symbol : variable path
    location: class org.apache.jsp.addExercise_jsp
    + "/" + path
    ^
    5 errors
         org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:128)
         org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:351)
         org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:413)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:453)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:437)
         org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:555)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:291)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

  • How to get the full path or name of the Layer to which Filter is applied?

    Hi All,
              I have created a layer using some background image as source. How to get the name or ful path of the background image?
    I checked the documentation and found GetPathNameProc(SPPlatformFileSpecification*) function, but I couldn't get the parameter SPPlatformFileSpecification*.
    Is there any other way to get the file path of background layer in my custom filter?
    Thanks,
    Dheeraj

    If this is a client side application then I'd say look into drag-n-drop tutorials.
    i.e. drag file to your application, action listener fires, create File object giving you full name and path of users action.
    If this is a web application then look into the "multipart/form-data" content type specifications on how to upload files.
    i.e. user specifies file from <input type='file' ... /> type, submits, servlet receives data and recreates file locally on application server side.
    If you are thinking that all you need to send a file to a program is the full path and name in a textbox its a little bit more complicated then that.
    Good luck, hope that helps!

Maybe you are looking for

  • How to use HR_MAINTAIN_MASTERDATA to terminate an employee

    Greetings experts: I'm working on an inbound interface that, among other things, can terminate an employee.  I'm new to ABAP and so it was recommended to me early on to record PA40 for this action.  That seemed to be working great until they added a

  • AJAX  like screen movement in Webdynpro

    Hi Experts,    I saw a video demonstration on sdn "https://wiki.sdn.sap.com/wiki/display/EmTech/IslandsWDA_MHO"  where with the new service pack we can move trays or other UI elements on the screen just by holding the mouse button on them like in AJA

  • Unable to deploy java

    Hi everyone i am not able to deploy java . Please do guide me.i am using sccm2012 r2 https://social.technet.microsoft.com/Forums/systemcenter/en-US/af6d3a92-ab97-406b-a1c6-67b64b2c65e2/java?forum=configmgrgeneral#af6d3a92-ab97-406b-a1c6-67b64b2c65e2

  • Synching Bookmarks Fails & Corrupts Safari ?

    The first time I manually synched my Safari bookmarks it was successful, however since then whenever I manually synch my bookmarks (several hundred ) to my iPod touch, the synching in not successful. Usually I am unable to open the bookmarks or none

  • How do I turn off the low battery alert for my wireless keyboard?

    The question is in the subject line. I find it kind of annoying to have to keep closing the alert window, and am still able to use the keyboard for a while past when the low battery alerts began. I tried system preferences for both alerts and for the