开发者

getenv() not working

I've created a stand alone a java application in Ubuntu 10.04 using Netbeans 6.9. I'm not able to use use the getenv() command in Netbeans, though if i create a separate java file in gedit and compile it in the terminal then it gives the desired output.

System.out.println(System.getenv("TRGRAPH"));

The above code when executed through t开发者_运维技巧he terminal gives the desired output but the same code if i try to run in Netbeans then it returns a null string.

Can anyone tell me how to get the output using netbeans??


You need to launch Netbeans from the same terminal after you have set and exported TRGRAPH.

Example, in a terminal:

$ export TRGRAPH=foo
$ netbeans&


I use Eclipse, not NetBeans, but I bet they are similar. Look for a dialog that controls how your program gets launched. This dialog probably has a place where you can specify environment variables that should be set when your app is launched.

The other alternative is to set the environment variable before you launch Netbeans.


It means that TRGRAPH is not defined in the process. The environment gets inherited from the environment of Netbeans. Make sure, that Netbeans gets the variable, e.g., by starting it from a command line or by invoking it using a shell script sourcing your .bashrc (or wherever you define TRGRAPH).


Alternatively, you can start an external Java process using the ProcessBuilder and pass it any environment you like. Quite complicated, but very flexible.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜