System属性和环境变量有什么区别? [英] What's the difference between a System property and environment variable

查看:276
本文介绍了System属性和环境变量有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不清楚这一点。当我运行java应用程序或在applet查看器中运行Applet(在IDE环境中), System.getProperty(java.class.path)给我一样的作为 System.getenv(CLASSPATH)这是我的env变量中定义的CLASSPATH。



但是当我将我的小程序部署到Web服务器并从与客户端相同的计算机访问它,我得到两个不同的结果。 ( System.getProperty(java.class.path)仅指向JRE主页和 System.getenv(CLASSPATH)返回null)。



这里有一些其他的事情让我想起来:



对于小程序部分,env var JAVA_HOME在浏览器中部署Applet以及Applet Viewer时,我得到相同的结果。



如果我在系统级别定义一个env变量,并使用 getenv(envName)结果是 null 。有没有办法我可以定义一个并在我的Java程序中得到它?

解决方案

环境变量是特定于操作系统的。属性仅限JVM。


I am not clear about this. When I run a java App or run an Applet in applet viewer, (in the IDE environment), System.getProperty("java.class.path") gives me the same as System.getenv("CLASSPATH") which is the CLASSPATH defined in my env variable.

But when I deploy my applet to webserver and access it from the same computer as a client, I get different results for the two. (System.getProperty("java.class.path") only points to JRE home and System.getenv("CLASSPATH") returns null).

And here is some other things that make me wonder:

For the applet part, the env var JAVA_HOME, I get the same result when deploying the applet in a browser as well as Applet Viewer.

And if I define myself a env variable at system level, and use getenv("envName") the result is null. Is there anyway I can define one and get it in my Java program?

解决方案

Environment variables are specific to the operating system. Properties are JVM only.

这篇关于System属性和环境变量有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆