getenv() 不工作
我使用 Netbeans 6.9 在 Ubuntu 10.04 中创建了一个独立的 java 应用程序。我无法在 Netbeans 中使用 getenv() 命令,但如果我在 gedit 中创建一个单独的 java 文件并在终端中编译它,那么它会给出所需的输出。
System.out.println(System.getenv("TRGRAPH"));
上面的代码通过终端执行时会给出所需的输出,但如果我尝试在 Netbeans 中运行相同的代码,则会返回空字符串。
谁能告诉我如何使用 netbeans 获取输出?
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 the 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??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
设置并导出 TRGRAPH 后,您需要从同一终端启动 Netbeans。
例如,在终端中:
You need to launch Netbeans from the same terminal after you have set and exported TRGRAPH.
Example, in a terminal:
我使用 Eclipse,而不是 NetBeans,但我敢打赌它们是相似的。寻找一个控制程序如何启动的对话框。此对话框可能有一个位置,您可以在其中指定启动应用程序时应设置的环境变量。
另一种选择是在启动 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.
这意味着TRGRAPH在进程中没有被定义。该环境继承自 Netbeans 环境。确保 Netbeans 获取该变量,例如,通过从命令行启动它或使用 shell 脚本采购您的
.bashrc
(或在您定义 TRGRAPH 的任何地方)来调用它)。或者,您可以使用 ProcessBuilder 启动外部 Java 进程,并将其传递给您喜欢的任何环境。相当复杂,但非常灵活。
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.