GetProperty

How can I obtain the running jar file name (and full path) from the java application?

Why you need jar file path? If only to read/write setting, etc. to .ini file.
Don�t forget to decode URL to avoid %20 instead of blanks as follow:
try {
String str = URLDecoder.decode(jarFile.toString(), "UTF-8");
catch (UnsupportedEncodingException _ex) {};                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • How to return multiple values from a getProperty method

    Hi All,
    Even though I understand that getPropprty can return only one value. I just have a doubt. Is it possible to use a getProperty method of a bean like
    public String getemp_Info(){
    return emp_Id;
    return emp_Name;
    }also can any one explain me where and how to use private variables and public variables in a bean.
    R.Ramesh.

    I already have it I just wanted to know that is there any usage like the one I asked, anyway thanks for your suggestion.
    I have already used another getProperty method as balusc quoted.

  • Problem with System.getProperty( "com.stc.application.dataroot" ) in JCAPS6

    Hello everybody,
    I'm using JCAPS 6 but I have to follow a guideline of projects implemented with JCAPS 5.1.3.
    The project for example, has written for the logs-directory in method user initialize this code:
    // JCAPS uses JVM version 1.5
    logger.info( "--- BEGIN ------ JCAPS userInitialize" );
    String currRoot = System.getProperty( "com.stc.application.dataroot" );
    String log4j_props = currRoot + "/../../NameDirectory/" + collabContext.getProjectPath() + "/" +
    collabContext.getCollaborationName() + "_log4j.properties";
    With JCAPS 6 I don't know how to substitute "System.getProperty( "com.stc.application.dataroot" );" because with it don't function.
    Somebody can help me?
    Thanx!
    Fabrizio

    This is the correct code:
    // JCAPS uses JVM version 1.5
    logger.info( "--- BEGIN ------ JCAPS userInitialize" );
    String currRoot = System.getProperty( "com.stc.application.dataroot" );
    String log4j_props = currRoot + "/../../NoemaLife/" + collabContext.getProjectPath() + "/" + collabContext.getCollaborationName() + "_log4j.properties";
    but I have the same problem...

  • [JS CS3] Metadata getProperty path

    Hi,
    How to get the values of the members in a container in the metadata?
    I created my own xmp-document which contains this fragment:
    A
    B
    I tried this code:
    myMetadatPreferences.getProperty("http://www.kvd.fake/ns#", "kvd:a/rdf:Seq/rdf:li[1]");
    But is does not work.
    Please let me know how to get at the rdf:li members.
    Thanks, Kees

    Hah, I solved the problem myself.
    This is how it's done:
    myMetadatPreferences.getProperty("http://www.kvd.fake/ns#", "kvd:a[1]");
    Result: A
    :D

  • System.getProperty("user.name") not working without /etc/passwd, CentOS 4.3

    Dear all,
    I'm having trouble getting the system property user.name (which we need in our ant scripts) on our CentOS box. :(
    When running the program below thru
    java dumpproperties2
    it prints "user.name='?'" on our CentOS 4.3. On win32 it works. It turns out that if you add the account corresponding to the EUID to /etc/passwd it works correctly. However, we don't use passwd authentication but an enterprise wide LDAP-system. Our /etc/nsswitch.conf says:
    passwd: files ldap
    One work around is to replace the java executable with a script that does
    /path/to/jdk/bin/java -Duser.name=$USER -Duser.home=$HOME $@
    Used jdk is j2se 1.5.0_13 Linux 32-bit.
    Some questions for the experts:
    1) Is there any other way?
    2) Is it a known issue that Linux versions of the jdk just looks in /etc/passwd to map uid to user name (and home dir) instead of doing what the rest of the system, like whoami, does? I haven't found anything in either the readme or installation instructions, nor in the bug db.
    Br, Jesper Tr�g�rdh
    public class dumpproperties2 {
        public static void main(String[] args) {
         String s = System.getProperty("user.name");
         System.out.println("user.name='" + s + "'");
    }

    Does this work?
    //public final class System
    public static String getenv(String name)Then you can access the USER environment from inside Java.

  • Using getProperty in my Java code.

    I am reading the attached XML file into my Java classes.
    <Config>
    <Properties>
         <entry key="rmi.remotecontrol.port">30</entry>
    </Properties>
    <AListener>
              <Subscriber></Subscriber>
              <Database>
                   <URL>jdbc:oracle:thin:@0.0.0:1521:dev</URL>
              </Database>
    </AListener>
    </Config>
    My Java code displays the correct output when I say:
    System.out.println("The RMI Port name property: " +  prop.getProperty("rmi.remotecontrol.port"));
    Output : 30Now,if I want to get the URL address of the database,and when I use
    System.out.println("The RMI Port name property: " +  prop.getProperty("Database.URL"));
    Output is null.How do I get the value of the URL using getProperty?
    Thanks,

    you're a complete idiot. seriously. three separate threads, days apart, each with the same mistake in, pointed out by me several times each thread, links to exactly the documentation you need, code actually pasted into the thread from the documentation, several patient explainations, and you still haven't bothered actually listening to me
    other posters beware: check this fools posting history for an insight into how they repeatedly ignore advice on this problem before deciding whether it's worth your effort replying - it isn't. this clown simply ignores being told directly what is wrong here, and even ignores being given the exact fix. no point replying
    http://forum.java.sun.com/thread.jspa?threadID=5155898&messageID=9589500#9589500
    http://forum.java.sun.com/thread.jspa?threadID=5153393&messageID=9577681#9577681
    http://forum.java.sun.com/thread.jspa?threadID=5152929&messageID=9575638#9575638
    and still you don't get it. give up programming, you're not cut out for it. it involves an attention span and the ability to listen to advice

  • Populating combobox in jsp page from javabean using jsp:getProperty tag

    hi,
    i am new to jsp, so i don;t know how to populate a combobox in jsp page with productid attribute from a javabean called Bid . i want to have a code to automatically populating combobox using the attribute value from javabean.
    please reply me.
    <jsp:useBean id="bidpageid" class="RFPSOFTWARE.Bid" scope="session" />
    <jsp:setProperty name="bidpageid" property="*"/>
      <table  width="50%" align="center" border="0">
       <tr>
        <td  width="30%" align="left"><h4><b><label>Date (dd/mm/yyyy) </label></b></h4> </td>
        <td><input type="text" name="date" size="11" maxlength="10" readonly="readonly" value="<jsp:getProperty name="bidpageid" property="date"/>"  > </td>
      </tr>
      <tr> <td > </td> </tr>
      <tr>
        <td  width="30%" align="left"><h4><b><label>ProductId </label></b></h4> </td>
        <td><select name="productid" tabindex="1" size="1" >
          <option  value="<jsp:getProperty name=bidpageid" />Sachin</option>
          <option value="Hello">Vishal</option>
        </select></td>
      </tr>  and the javabean for Bid is as follow :
    import java.util.Date;
    import RFPSOFTWARE.Product;
    public class Bid{
    private Product product;
    private Integer bid_id;
    private String description;
    private Date date= new Date();
    public Integer getBid_id() {
    return bid_id;
    public Date getDate() {
    return date;
    public String getDescription() {
    return description;
    public Product getProduct() {
    return product;
    public void setBid_id(Integer bid_id) {
    this.bid_id = bid_id;
    public void setDate(Date date) {
    this.date = date;
    public void setDescription(String description) {
    this.description = description;
    public void setProduct(Product product) {
    this.product = product;
    }

    No Sir,
    I think I did not explained clearly.what I try to say is I dont want to use JSTL.I am using only Scriptlets only.I can able to receive the values from the database to the resultset.But I could not populate it in Combobox.
    My code is :
    <tr>
    <td width="22%"><font color="#000000"><strong>Assign To Engineer</strong></font></td>          
    <td width="78%">
         <select NAME="Name" size="1">
    <option><%=Username%></option>
    </select> </td>
    </tr>
    in HTML
    and in Scriptlets:
    ps1 = con.prepareStatement
              ("SELECT Username FROM Users");
              rs2=ps1.executeQuery();
              System.out.println("SECOND Succesfully Executed");
              while(rs2.next())
                   System.out.println("Coming inside rs2.next loop to process");
                   Username=rs2.getString("Username");
                   System.out.println("Success");
                   System.out.println("The value retrieved from UsersTable Username is:"+Username);
    In the server(Jboss console) I can able to display the username but I could not populate it in the Combobox .
    Can you now suggest some changes in my code,Please..
    Thanks a lot
    With kind Regds
    Satheesh

  • System.getProperty("user.dir") returns "/home/user" on Linux

    Has anyone else had the error when launching a jar from Linux (just by clicking it), System.getProperty("user.dir") returns the "/home/user" (or "~") value instead of the folder that the jar is in? Essentially, it returns "user.home" instead of "user.dir".
    This does not happen when I start the application from command line.
    (I know its not swing, but I wasn't sure where to post it)
    Is this just a simple Linux setting that isn't enabled by default? Ubuntu already made the file association after using apt-get to install Java 6.
    Cheers.
    -FBL

    Because, semmingly, the command is being set off as
    java -jar relative/pat/to/file.jarwhen you double click it, rather than
    cd relative/path/to
    java -jar file.jarIf you don't like this, I would say to find a Linux, preferably Ubuntu, forum and ask there if it is possible to change that handling, and if not, request that a cahnge be made to the code to change that handling. But, in any case, I doubt you are going to get an answer here about it.

  • Xalan applet getProperty securityException

    If I use xalan2.2D6 for xsl transformation in an applet I get the following securityException:
    Is ther a proper way to solve this problem ?
    I hacked TreeWalker.java and removed the getProperty calls. It works for me but I'm shure its not the best way
    to do it.
    Regards Christian
    java.security.AccessControlException: access denied (java.util.PropertyPermission user.dir read)
         at java.security.AccessControlContext.checkPermission(AccessControlContext.java:272)
         at java.security.AccessController.checkPermission(AccessController.java:399)
         at java.lang.SecurityManager.checkPermission(SecurityManager.java:545)
         at java.lang.SecurityManager.checkPropertyAccess(SecurityManager.java:1278)
         at java.lang.System.getProperty(System.java:560)
         at org.apache.xml.utils.TreeWalker.<init>(TreeWalker.java:149)
         at org.apache.xml.dtm.ref.dom2dtm.DOM2DTM.<init>(DOM2DTM.java:1563)
         at org.apache.xml.dtm.ref.DTMManagerDefault.getDTM(DTMManagerDefault.java:185)
         at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:585)
         at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1037)

    I have the same problem.
    Does anybody know elegant solution for this problem ?
    Please...
    Sincerely,
    Victor Letunovsky
    AlarIT programmer
    http://www.AlarIT.com

  • Properties does have getProperty method

    I have this code but the Properties does have the method getProperty()
    import java.io.*;
    import java.sql.*;
    import java.util.*;
    public class TestCode {
        static final String PROPERTY_FILE="JDBC-ODBC Driver.properties";
        String driverName, url, user, password;
        /** Creates a new instance of TestCode */
        public void access() {
            try{
                /* Create an object of the Properties class and load properties. */
                Properties prop=new Properties();
                prop.load(new FileInputStream(PROPERTY_FILE));           
                driverName=prop.getProperty("driver");  // Retrieve driver information.           
                url=prop.getProperty("url");    // Retrieve JDBC URL.
                user=prop.getProperty("user");  // Retrieve user name.
                password=prop.getProperty("password");  // Retrieve password.
                /* Initialize and load a driver. */           
                Class.forName("driverName");
                /* Establish a connection with a database. */
                Connection con=DriverManager.getConnection(url,user,password);
                /* Create Statement object. */
                Statement stmt=con.createStatement();
                /* Executes a SQL query to retrieve a ResultSet. */
                ResultSet rs=stmt.executeQuery("SELECT * FROM Registered_Users_Information");
                /* Iterate through the ResultSet to display data. */
                while(rs.next()){
                    System.out.println(rs.getString("UserName"));
                    System.out.println(rs.getString("Password"));
                con.close();
            }catch(Exception ex){
                ex.printStackTrace();
        public static void main(String args[]){
            TestCode t=new TestCode();
            t.access();
    }Please show me the problem.
    Thanks.
    Nguyen_Tom

    I used this code but it does not exist. Has anyone
    tell me why or please five me an advise? The object
    prop does not has the method load.
    Properties prop=new Properties();
    prop.load(new FileInputStream(PROPERTY_FILE));Thanks a lot.
    Nguyen_TomRefer to the JDK spec since 1.0, Properties should have all the methods you said you didn't have.
    Did your program throw any error messages?? Could you show me?
    :D

  • jsp:getProperty.... in a taglib-tag ???

    Hi !
    I have taglib where I have defined a lots of classes and one of them I have a attribute who should be dynamic. I have tryed this:
    <easyTagz:submit iteration='<jsp:getProperty name='submission' property='maxCount'/>' />
    but it dosen`t seem to work....
    Any suggestion :-)

    Dosen`t seem to work, have tryed and gets this error message:
    org.apache.jasper.JasperException: Unable to compile class for JSP
         at org.apache.jasper.servlet.JspServlet.loadJSP(JspServlet.java:567)
         at org.apache.jasper.servlet.JspServlet$JspServletWrapper.loadIfNecessary(JspServlet.java:177)
    Any suggestion ???

  • Can we write %System.getProperty("CONFIG_MODE");% this stmt in EL or jstl

    Hi everyone,
    Can we write below statement in EL or jstl instead of using Scriplet.
    <%System.getProperty("CONFIG_MODE");%>
    Thanks,
    Nihar.T

    getting a system property is too much on the business logic side. You could create a bean that returns the system property as a member, like:
    public class PropertyBean
    public String getConfigMode()
      return System.getProperty("CONFIG_MODE");
    }then simply use EL in your JSP(s) to get the value from that bean. Of course you could just make the getConfigMode() method part of an existing bean you are using.

  • Enums for System.getProperty(...) method in Java API?

    Just had a thought today as a result of a colleaugue mis-spelling "file.separator" in a System.getProperty() call:
    How about an enum for the above method (e.g. SystemProperty) that has all the known properties and the String method for any prop not included in the enum?
    Am I being too greedy or pedantic about type-safety?
    Appreciate your feedback.
    Cheers,
    Ali
    Edited by: user7627452 on 30-Apr-2012 19:09

    Yes. The whole idea is that anybody can add their own. As opposed to an API.

  • System.getProperty("user.region") in JDK version 1.3 vrs. 1.4

    Hi guys,
    I wonder why, when I set the following instruction to detect the regional settings, I got different results using 1.3.1 vrs. 1.4.1?
    String slRegion = System.getProperty("user.region");
    If I use 1.3.1 then I got the right result, but if I use 1.4.1 I got a null value.
    I need to use JDK 1.4.1, that's why I'm interested in getting the answer.
    TIA.

    As I want to know the 2 letters of the countries, such as:
    IN_USA = "US";
    ES_MEXICO = "MX";
    ES_ARGENTINA = "AR";
    ES_BOLIVIA = "BO";
    ES_CHILE = "CL";
    ES_COLOMBIA = "CO";
    ES_COSTARICA = "CR";
    ES_REPDOMINIC = "DO";
    ES_ECUADOR = "EC";
    ES_SALVADOR = "SV";
    What would it be the syntaxis (line code) to get this info?
    I appreciate your help

  • Jsp:getProperty in tag attributes

    Hii....
    I have a custom tag that displays some information based on an attribute of the tag. I want to set information from a bean to the attribute using the jsp:getProperty tag...
    I want to do something like.......
    <mytagprefix:MyTag attribute1='<jsp:getProperty id="myID" property="name"/>' />
    If I do it right now I am getting the string <jsp:getProperty id="myID" property="name"/> inside the my TAG.
    any help will be appreciated.
    sanjay.

    I'm a bit rusty on custom tags, so maybe this isn't the best solution, but until you find a better one you can try '<%= myID.getName() %>' as the attribute.

  • [svn:bz-trunk] 20505: Bug: Watson #2818669 - AbstractAmfInput uses System. getProperty in Constructor leading to AccessControlException when using in Applet

    Revision: 20505
    Revision: 20505
    Author:   [email protected]
    Date:     2011-03-01 07:31:55 -0800 (Tue, 01 Mar 2011)
    Log Message:
    Bug: Watson #2818669 - AbstractAmfInput uses System.getProperty in Constructor leading to AccessControlException when using in Applet
    QA: Yes
    Doc: No
    Checkintests: Didn't run - the change was to wrap the System.getProperty in a try/catch that would have caused the SecurityException, so no real functionality change that could affect the check-in tests.
    Modified Paths:
        blazeds/trunk/modules/core/src/flex/messaging/io/amf/AbstractAmfInput.java

Maybe you are looking for