System.getProperty doesnot work

Hi,
I have a piece of code where I try to get a env variable VTNAME in my java application. Code snippet below
     //this function creates a session.
     public void setSession(configParams params) throws Exception {
          boolean done = false;
          int retryCount = 0;
          mVTName = params.getFactoryName();
          System.out.println(System.getProperty("VTNAME"));
It returns me null. And when i do
:/home/santsat > echo $VTNAME
dbusd1.srv.uk.deuba.com:8092/tcp:
Any thoughts o what is wrong in the code?
Thanks
Message was edited by:
chabhi

Java's system property is not the same as environment variable.
To get environment variable, use System.getenv().
If you start your java app with -DVTNAME= then you can use System.getProperty().
Budyanto

Similar Messages

  • Why System.setProperty doesnot work?

    Dear ALL
    i Want to use System.setProperty to set CLASSPATH
    but i find it doesnot work. after run it,
    CLASSPATH is same as before
    below is code
    before running java Test
    classpath is null
    after running java Test
    classpath is still null,
    How do i set classpath during program running time
    and keep the change after running time?
    import java.util.*;
    public class Test
    public static void main(String[] args)
    System.out.println(System.getProperty("java.class.path"));
    System.setProperty("java.class.path","C:\\C\\subc;"+System.getProperty("java.class.path"));
    System.out.println(System.getProperty("java.class.path"));

    Any properties you change using System.setProperty() go away as soon as the JVM exits -- they are changed in memory only.

  • Java 7 u45 System.getProperty returns null

    After upgrade to u45, our web launch application stopped working. it failed at System.getProperty("myproperty").
    "myproperty" is defined as a
    <resources>       
    <j2se version="1.6+" initial-heap-size="64m" max-heap-size="256m"/>
           <jar href="nms_wsclient.jar" download="eager" main="true"/>
           <jar href="commons-httpclient.jar" download="eager"/>      
          <jar href="commons-codec.jar" download="eager"/>       
          <jar href="commons-logging.jar" download="eager"/>       
          <jar href="log4j.jar" download="eager"/>       
          <property name="myproperty"   value="http://138.120.128.94:8085/"/>
        </resources>
    with older version java ,System.getProperty("myproperty") works fine to return the value, but with u45 it returned null.
    Does anyone have the same problem? any idea how to fix it or work around it?
    Thanks,
    Zhongyao

    So did you succeed with the jnlp template ?
    After frustrating hours of that information useless JNLPSigningException trial & error, It seems that as :
    1. You can't make the j2se version variable
    2. You can't have your own variable property/values
    I've opened a bug report...
    The documentation is atrocious, with a vague "we reserve the right to blacklist variable elements, but we will never say which ones".
    The JNLP example in the various example is a joke - Its a hello world jnlp, not a real world one.
    The JNLPSigningException must have been written my the same guys at Microsoft that did the "An Unknown Error As Occurred".
    I've had to clear the cache at every test, seems that the JNLP Template check didn't get the new updated JNLP from the web server.
    /rant over
    I think I'll try to bypass that JNLP property mess and get javaws to download my own "jnlp name".xml.config...

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

  • Applet, System.getProperty question

    I am trying to develop a simple applet that would capture the NT user name with System.getProperty("user.name"). This will not work with servlet because it will only return the server user.name. With applets running on clients systems, I was hoping that this will work. My applet has only 1 button and 1 text field. It runs fine in a debug mode in Forte 2.0. It generates an error msg when I run in in Forte. It doesn't do anything if I add the class to a html file. Am I on the right track here or what do I need to do to get this to work?
    private void button1ActionPerformed(java.awt.event.ActionEvent evt) {
    String login = System.getProperty("user.name");
    textField1.setText(login);
    This works in a debug mode in Forte, but fails when I run it. This is the error message:
    Exception occurred during event dispatching:
    java.security.AccessControlException: access denied (java.util.PropertyPermission user.name 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 LoginApplet.button1ActionPerformed(LoginApplet.java:40)
    at LoginApplet.access$0(LoginApplet.java:39)
    at LoginApplet$1.actionPerformed(LoginApplet.java:20)
    at java.awt.Button.processActionEvent(Button.java:329)
    at java.awt.Button.processEvent(Button.java:302)
    at java.awt.Component.dispatchEventImpl(Component.java:2595)
    at java.awt.Component.dispatchEvent(Component.java:2499)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:319)
    at java.awt.EventDispatchThread.pumpOneEvent(EventDispatchThread.java:103)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:84)

    Hi,
    As you can see you received a Security exception, for a good reason. If you could access a username and/or password then your computer could be compromised. Anyone could then write an unseen applet embedded in their web page that gathers username/password for any computer that requests the web page. The security manager on that specific PC (or web browser) would have to be modified specifically to allow this sort of access, which is not advised because then anyone else with this type of applet could get the same information that you are attempting to get (if you request a web page on another site with that applet requesting you system information).
    Hopefully this helps.

  • Sample code that allows System.inheritedChannel() to work?

    Hi,
    I would like to create a C program, which will launch a Java runtime. I want the C program to open a listening socket, then pass that listening socket to the started Java VM.
    I should be able to do this, and have the java VM inherit the listening socket, and then in the Java program, I should be able to get the listening socket with System.inheritedChannel().
    In theory, anyway, all the docs seem to state that this is possible. But the problem is that I haven't found any code that does this. I'm not sure how I should setup the listening socket so that its the one that is picked by the inheritedChannel() call. What happens if my C program has multiple sockets, both connected and listening? How is the correct one determined? And do I have to have any special implementation of SelectorProvider?
    Finding a working sample would really help me figure this out. Or, just any program that already uses this mechanism somewhere.
    Can someone point me to such a sample?
    Thanks,
    Greg

    The following 'c' code will first create a LISTEN socket then pass it to the Java application following. This, with the previous post show both passing connected clients as-well-as service sockets to java via System.inheritedChannel().
    #include "stdnet.h" // platform specific network headers
    int
    main(int argc,char *argv[])
         pid_t     childPid = (pid_t)-1;
         // setServiceOnHostPort() creates bound LISTEN socket
         int          service     = setServiceOnHostPort("127.0.0.1",13333);
         fprintf(stderr,"service socket is %d, on port %d\n",
              service,getServicePort(service));
         // create child process in which to start the jvm
         if               ((pid_t)0 > (childPid = fork()))
              fprintf(stderr,"Cannot fork(), errno = %d\n",errno);
              exit(-1);
         } else if     ((pid_t)0 != childPid) {
              // close replace the tty fd with our service (LISTEN) socket
              dup2(service,STDIN_FILENO);
              // close the others, just in case
              dup2(-1,STDOUT_FILENO);
              dup2(-1,STDERR_FILENO);
              // stdin == service so we can close service now
              close(service);
              execvp(argv[1],&argv[1]);
              /* Failed to start application, pause before exiting w/ 123 */
              _exit(123);
         } /* if          ((pid_t)0 > (childPid = fork())) */
         // parent can leave now, of course its better to see if jvm actially
         // started here by looking for child's exit code of 123.
         return(0);
    } /* int main(int argc,char argv[]) /
    Now the java code.
    import java.io.File;
    import java.io.PrintStream;
    import java.net.ServerSocket;
    import java.net.Socket;
    import java.nio.channels.ServerSocketChannel;
    import java.nio.channels.SocketChannel;
    public class jInetdApp
         public static void main(String[] args)
              throws Exception
              System.setOut(new PrintStream(new File(
                   System.getProperty("user.dir") + "/java-inetd.out")));
              System.setErr(new PrintStream(new File(
                   System.getProperty("user.dir") + "/java-inetd.err")));
              Object stdInObject = (Object)System.inheritedChannel();
              // started w/ connected socket
              if (stdInObject instanceof SocketChannel)
                   SocketChannel channel =
                        (SocketChannel) stdInObject;
                   Socket socket = channel.socket();
                   System.err.println("channel: " + channel);
                   System.err.println("socket: " + socket);
                   PrintStream ps =
                        new PrintStream(socket.getOutputStream());
                   ps.println("Hello world");
                   ps.flush();
                   ps.close();
                   socket.shutdownInput();
                   socket.shutdownOutput();
                   socket.close();
              // started with service (LISTEN) socket
              } else if (stdInObject instanceof ServerSocketChannel) {
                   ServerSocketChannel channel =
                        (ServerSocketChannel) stdInObject;
                   ServerSocket socket =
                        (ServerSocket)channel.socket();
                   System.err.println("channel: " + channel);
                   System.err.println("socket: " + socket);
                   Thread.sleep(30000);
                   socket.close();
              // started from command line??
              } else {
                   System.err.println("stdInObject: " + stdInObject);
              } if (stdInObject instanceof SocketChannel)
              System.err.flush();
              System.out.flush();
         } // public static void main(String[] args)
    } // public class jInetdApp
    I hope this is helps.
    cj

  • Getting cell id in java me using System.getProperty

    Hi all
    I wish to get the cell id of the cell (I know it had been asked for more than a million times) that my nokia phone is currently connected to with the api listed here
    [http://wiki.forum.nokia.com/index.php/CS000947_-_Getting_Cell_ID_in_Java_ME|http://wiki.forum.nokia.com/index.php/CS000947_-_Getting_Cell_ID_in_Java_ME]
    As stated,
    System.getProperty("com.nokia.mid.cellid") works on S60 3rd Ed
    System.getProperty("Cell-ID") works on S40 3rd Ed
    However, I am unable to do so on N82, anyone have any idea why is that so?
    Or is there any kind soul with N95 can tell me whether it works on N95?

    yes.. I saw that thread before I posted this.. but the piece of code mentioned in the thread does not make use of the api listed in the wiki right?
    In fact, I'm not very clear as to what that mentioned code is doing.
    Moreover, my point would be, how come the api is listed in the wiki in that case.. that is, if it does not work.. :/

  • Alternative to System.getProperty("microedition.hostname")

    Hey is there any other alternative for 'System.getProperty("microedition.hostname")' to get the ip address of the device running the j2me midlet ??
    When you run the midlet on the emulator, System.getProperty("microedition.hostname") returns the PC's Name, but on a Nokia series 40(3rd E) device, it returns null.
    So is there an alternative to this to select the device's ip address ?

    First this is a pretty specific question which applies to a specific device rather than to reflection/reference. You might want to look for a forum that addresses the specific device.
    Second, you can print the system properties normally. Whether you can do that on the device depends on the device. If you succeed you might find an alternative.
    Third normally one uses the java.net.IpAddress to get a device IP. Does that not work for that device?

  • Salary Statement doesnot work

    Dear all:
    we met a very urgent issue about our sap portal configuration.
    i installed a sap portal 7.00 SP11 and the backend system is ECC6.0.
    others functions are working now , but "salary statement" doesnot work.
    i got this following error after pressed salary statement , so pls help me !
    <b>The initial exception that caused the request to fail, was:
       java.lang.ArrayIndexOutOfBoundsException: -1
        at com.sap.mw.jco.JCO$Record.getString(JCO.java:12761)
        at com.sap.aii.proxy.framework.core.JcoBaseTypeData.getElementValueAsString(JcoBaseTypeData.java:669)
        at com.sap.tc.webdynpro.modelimpl.dynamicrfc.DynamicRFCModelClass.getAttributeValueAsString(DynamicRFCModelClass.java:427)
        at com.sap.xss.hr.rep.model.rfwmodel.Hrxss_Ser_Rfw_Rfc_Get_Form_Output.getHeight(Hrxss_Ser_Rfw_Rfc_Get_Form_Output.java:179)
        at com.sap.xss.hr.rep.fcrfw.FcRepFramework.callRfcGetForm(FcRepFramework.java:395)
        ... 45 more</b>
    best Regards
    scott

    Dear James:
    thank you very much for your feedback !
    i reconfigured the ESS in the backend system , now the error info disappeared.
    but i got the other error info:
    <b>Error when calling method INIT of class CL_HRXSS_REM </b> 
    i have no idea for this error info now .
    can you give me some instruction?
    thanks again!
    best Regards
    scott

  • Internal and external microphone doesnot working on HP probook 6550b

    HP probook 6550b.  Windows 7 Pro SP1 64bit.
    Sound works without any problems but my microphone suddenly stops working today. 
    Usually i use my internal microphone.
    I tried to plug in one of my external microphones to mic jack and it also doesnot working. I check my 2 external microphones on other PC and they both are woking properly.
    1) Nothing new was installed today.
    2) To fix this i tried to swich in sound properties default device but i dont see any green volume level behind mic images for both.
    3) I removed all audio drivers 
    4) After PC was restarted windows installed default drivers but i still cannot record any sound. (Checked in skype and by green record level indicator in sound properties)
    5) Also for default windows drivers i tried to switch my default microphone in 'sound' window settings and also plug in and out my external mics and without results.
    Screen shot of windows after default windows drivers was installed:
    What it can be?
    Thanks.

    First question, i would answer yes :
    About this mac >Materiel > Audio (intégré) > audio haute définition Intel > microphone interne > connexion interne
    Second question :
    in system preference > microphone interne  is black and not grey.
    bars "sound test" near menu "entry level" does not move at all even if I shout...
    Third question :
    The power supply has been totaly replaced by a new one.
    4rth :
    Yes, no problem with speakers integrated or with the one of the headset...
    On skype : i Hear but can not speak.
    (i tested the headset on a PC, it works)

  • System.getProperty("user.home") is giving diferent results on diff versions

    I am working on windows 2000. When I try to get user.home using System.getProperty it gives me c:\documents and settings\my name.
    But the same things when tried on a windows 2003 server tries to look in c:documents and settings\default directory. Why is this?
    Please help.....

    In XP, the environment variable USERPROFILE is set to C:\Documents and Settings\<username>, and that value is picked up for user.home. Since the "user's home directory" varies by os, there will be variations. 98 is different than Linux than XP, etc.

  • System.getProperty("user.dir") different in Ubuntu?

    HI. I have this application which when the user presses the Help button an HTML user guide is shown.
    this is done using:
    String userDir = System.getProperty("user.dir");
    System.out.println(userDir);
    Desktop d = Desktop.getDesktop();
    File f = new File(userDir);
    URI u = new URI(f.toURI().toString()+"User_Guide/index.htm");
    System.out.println(u.toString());
    d.browse(u);This works on Windows machines, but when tested on Unix Ubuntu the user guide does now show.
    The System.getProperty("user.dir") returns users/j/john/ which is not the complete directory. How can I fix this so that the Help button works on both platforms?Thanks!
    Edited by: player123 on Jun 9, 2009 10:54 AM

    ++
    Make sure its Sun's Java no OpenJDK or others.
    $ java --version
    also echo $JAVA_HOME
    it depends how its linked on yours.
    Even if you install the Sun's JDK you must properly link it and/or set and export its home ;)

  • System.getProperty("user.dir") cannot rerturn the package directory.

    i have a class belong to package suyuan
    the class file is located at
    D:\Profiles\cyc025\Desktop\suyuan\test.class
    i try to execute System.getProperty("user.dir") inside test.class.
    i get D:\Profiles\cyc025\Desktop
    but i wish there is a java api which can return
    D:\Profiles\cyc025\Desktop\suyuan
    how can i do so?
    thank you.
    regards
    yan cheng

    The system property "user.dir" returns the current working directory. The "suyuan" is a part of the java package of test.class - it has nothing to do with each other. If you want your string you need to create it via
    String pn = getClass().getName();
    int i = pn.lastIndexOf('.');
    pn = pn.substring(0, i);
    String mine = System.getProperty("user.dir") + File.separatorChar + pn;

  • Using System.getProperty in the app, but still not signing the jar file

    Is there a way to use the System.getProperty call in the app but not sign the jar? I get the security exception when launched using WebStart?
    Any help appreciated.

    Yes. Don't use Web Start, and you'll have no problems.
    Seriously, the security exception is there by design. If you must call System.getProperty, you need to sign your jars -- though personally, I think there are situations where signing your jars to make Web Start work is a needless complication.
    However, if you still need a tool to deploy updates and such, I recommend Deploy Director from Sitraka.

  • Trackpad doesnot work when battery is charging

    Dear all,
    I got a new macbook less than a month ago,
    When ever my battery in on charge the trackpad doesnot work
    please help me

    http://www.bresink.de/osx/TemperatureMonitor.html
    After downloading it and running the program, I got
    16C or 60F. Which is clearly wrong. I quit the
    program several times and got the same reading. I
    even set the update time to a much shorter rate, and
    still the same reading. A reboot of the system seems
    to have fixed it temporarily. Its at 48C or 114F.
    The program doesn't update the temperature for some
    reason. Even running the Mac at near 100% CPU the
    temperature monitor stays at 48C. Clearly this
    doesn't work with the MBP yet. Regarding updating
    every few seconds. You have to reboot to get new
    readings.
    Thanks for giving me that link though.
    I'm using it as we speak and I'm getting flawless results. I would check your installation and run a hardware check as well.

Maybe you are looking for