如何在mac上设置java环境变量 [英] How to set java environment variable on mac

查看:416
本文介绍了如何在mac上设置java环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置可以在Mac OS X Lion上使用 System.getenv()读取的Java环境变量?我在Eclipse中开发。

How do I set a java environment variable that can be read with System.getenv() on Mac OS X Lion? I developing in Eclipse.

我在终端中使用了这个命令 export VAR_NAME = Value System.getEnv(VAR_NAME)返回 null

I used this command in the terminal export VAR_NAME=Value but System.getEnv(VAR_NAME) returns null.

我尝试过 java -DVAR_NAME = Value ,但没有执行任何操作。我只得到了java参数的帮助。

I tried java -DVAR_NAME=Value but nothing is executed. I only get the java arguments help.

我在我当前的项目文件夹中创建了文件 .bash_profile export VAR_NAME = Value 。它不起作用。

I created in my current project folder the file .bash_profile with the content: export VAR_NAME=Value. It's not working.

我还在中创建了一个文件夹 .MacOSX 在这个文件中,我使用XCode写了该属性及其值。没有任何工作。

I also created the folder .MacOSX with a single file inside environment.plist and in this file I wrote the property and its value using XCode. Nothing is working.

我该怎么做?

推荐答案

目前还不清楚你在做什么。如果您尝试为Java命令设置环境变量,那么您将从Eclipse 启动,那么简单的解决方案就是通过Eclipse命令启动器配置进行设置。另一个选择是:

It is not clear what you are actually doing here. If you are trying to set an environment variable for a Java command you are launching from Eclipse, then the simple solution is to set it via the Eclipse command launcher configuration. Another alternative is to:


  1. 退出Eclipse,

  2. 运行导出VAR_NAME =值,并且

  3. 从同一个shell实例启动Eclipse

  1. exit Eclipse,
  2. run export VAR_NAME=Value in a command shell instance, and
  3. launch Eclipse from that same shell instance.






重新制作您尝试的东西。


Re the things you tried.


我在终端中使用此命令导出VAR_NAME =值 System.getEnv(VAR_NAME)返回 null

如果您运行 export 命令,然后立即从相同的命令提示符启动命令,即应该工作。导出命令是告诉命令提示符使用的shell实例将 VAR_NAME 添加到其导出的环境变量列表到运行 export 命令。所有已准备好启动的子进程将不会看到更改

If you run the export command from a command prompt, and then immediately launch the command from the same command prompt, that should work. The export command is telling the shell instance used by the command prompt to add VAR_NAME to this list of environment variables it exports to child processes that started after running the export command. Child processes that have all ready been started won't see the changes.

我强烈怀疑您运行的导出 之后,您启动了Eclipse ...或者您没有从该shell实例启动Eclipse。如果这两个中的任何一个为真,则 export 命令不会影响Eclipse(默认情况下)传递给从Eclipse启动的任何Java程序的环境变量。 p>

I strongly suspect that you ran the export after you launched Eclipse ... or that you didn't start Eclipse from that shell instance. If either of those two is true, the export command wouldn't affect Eclipse's environment variables which it (by default) passes on to any Java program you launch from Eclipse.


我尝试过 java -DVAR_NAME = Value ,但没有执行任何操作。我只得到了java参数的帮助。

I tried java -DVAR_NAME=Value but nothing is executed. I only get the java arguments help.

由于以下几个原因,失败:

That fails for a couple of reasons:


  • -DVAR_NAME = ... 正在将系统属性设置为环境变量,

  • 您没有告知 java 您要开始的类的名称!

  • the -DVAR_NAME=... is setting a system property not an environment variable, and
  • you haven't told java the name of the class that you want to start!

我在我当前的项目文件夹中创建了文件 .bash_profile ,内容包括: export VAR_NAME =价值

只影响您创建的之后的文件。它不会影响现有的。

That only affects new shell instances that are launched after you created the file. It doesn't affect the existing one.


我还创建了一个文件夹.MacOSX在environment.plist和这个文件中有一个文件我使用XCode写了该属性及其值。

I also created the folder .MacOSX with a single file inside environment.plist and in this file I wrote the property and its value using XCode.

我不知道该怎么做。你在哪里创建该文件夹?

I've no idea what that would do. Where did you create that folder?

这篇关于如何在mac上设置java环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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