Eclipse 中的环境变量

发布于 2024-11-29 03:49:02 字数 579 浏览 4 评论 0原文

我能够从命令提示符运行一个示例 hadoop 程序,并尝试从 Eclipse 运行相同的程序,以便我可以调试它并更好地理解它。

对于命令行程序,一些环境变量在 .bashrc 中设置,并且在 .bashrc 中被读取为 System.getenv().get("HADOOP_MAPRED_HOME") hadoop 程序。但是,当我使用 System.getenv().get("HADOOP_MAPRED_HOME") 运行 java 程序时,从 Eclipse 我得到的是 null。

我尝试将 -DHADOOP_MAPRED_HOME=test 从 Eclipse 传递到运行时配置中的 VM 参数,但在独立程序中仍然为 null。如何使环境变量在Eclipse中可见?当我在 Eclipse 中迭代 System.getenv() 时,我看到很多变量,例如 DISPLAYUSERHOME > 以及其他。它们设置在哪里?我使用的是 Ubuntu 11.04。

I am able to run a sample hadoop program from the command prompt and am trying to run the same program from Eclipse, so that I can debug it and understand it better.

For the command line program, some environment variables are set in the .bashrc and the same are being read as System.getenv().get("HADOOP_MAPRED_HOME") in the hadoop program. But, when I am running a java program with System.getenv().get("HADOOP_MAPRED_HOME"), from Eclipse I am getting null.

I tried passing -DHADOOP_MAPRED_HOME=test to VM parameters in the runtime configurations from Eclipse, but still getting null in the standalone program. How to make the environment variables visible within Eclipse? When I iterate through System.getenv() in Eclipse, I see lot of variables like DISPLAY, USER, HOME and others. Where are they set? I am using Ubuntu 11.04.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

赏烟花じ飞满天 2024-12-06 03:49:02

您还可以定义仅在 Eclipse 中可见的环境变量。

转到运行 ->运行配置...并选择选项卡“环境”。

在此处输入图像描述

您可以在其中添加多个特定于您的应用程序的环境变量。

You can also define an environment variable that is visible only within Eclipse.

Go to Run -> Run Configurations... and Select tab "Environment".

enter image description here

There you can add several environment variables that will be specific to your application.

娇纵 2024-12-06 03:49:02

我为此创建了一个 eclipse 插件,因为我遇到了同样的问题。
请随意下载并为其做出贡献。

它仍处于早期开发阶段,但它已经为我完成了它的工作。

https://github.com/JorisAerts/Eclipse-Environment-Variables

在此处输入图像描述

I've created an eclipse plugin for this, because I had the same problem.
Feel free to download it and contribute to it.

It's still in early development, but it does its job already for me.

https://github.com/JorisAerts/Eclipse-Environment-Variables

enter image description here

开始看清了 2024-12-06 03:49:02

.bashrc 文件用于设置交互式登录 shell 使用的变量。如果您希望这些环境变量在 Eclipse 中可用,您需要将它们放在 /etc/environment 中。

The .bashrc file is used for setting variables used by interactive login shells. If you want those environment variables available in Eclipse you need to put them in /etc/environment.

邮友 2024-12-06 03:49:02

您可以通过向虚拟机发送 -Dhadoop.home.dir 来设置 Hadoop 主目录。要将这些参数发送到您在 eclipse 中执行的所有应用程序,您可以在 Window->Preferences->Java->Installed JREs->JRE 中设置它们。 (选择您的JRE安装)->编辑..-> (在“默认 VM 参数:”文本框中设置值)。您可以将 ${HADOOP_HOME} 替换为 Hadoop 安装路径。

选择用于在 Eclipse 中运行程序的 JRE

将 hadoop.home.dir 属性的值作为 VM 参数发送

You can set the Hadoop home directory by sending a -Dhadoop.home.dir to the VM. To send this parameters to all your application that you execute inside eclipse, you can set them in Window->Preferences->Java->Installed JREs-> (select your JRE installation) -> Edit.. -> (set the value in the "Default VM arguments:" textbox). You can replace ${HADOOP_HOME} with the path to your Hadoop installation.

Select the JRE you use for running programs in Eclipse

Sending the value for hadoop.home.dir property as a VM argument

痴者 2024-12-06 03:49:02

您还可以在 shell 中启动 eclipse。

在调用 eclipse 之前导出环境。

示例

#!/bin/bash
export MY_VAR="ADCA"
export PATH="/home/lala/bin;$PATH"
$ECLIPSE_HOME/eclipse -data $YOUR_WORK_SPACE_PATH

然后您可以在 Eclipse 上拥有多个实例,并拥有自己的客户环境(包括工作空间)。

You can also start eclipse within a shell.

You export the enronment, before calling eclipse.

Example :

#!/bin/bash
export MY_VAR="ADCA"
export PATH="/home/lala/bin;$PATH"
$ECLIPSE_HOME/eclipse -data $YOUR_WORK_SPACE_PATH

Then you can have multiple instances on eclipse with their own custome environment including workspace.

迷你仙 2024-12-06 03:49:02

我试图实现这一点,但是是在 MAVEN 构建的背景下。作为我的 pom.xml 配置的一部分,我引用了一个环境变量作为本地 JAR 路径的一部分:

<dependency>
  <groupId>the group id</groupId>
  <artifactId>the artifact id</artifactId>
  <version>the version</version>
  <scope>system</scope>
    <systemPath>${env.MY_ENV_VARIABLE}/the_local_jar_archive.jar</systemPath>
</dependency>

为了编译我的项目,我必须将环境变量定义为正如 Max 的回答所解释的那样,运行 Maven 构建的配置。我能够启动 Maven 编译,并且该项目可以正常编译。

但是,由于此环境变量涉及一些依赖项,Eclipse 的默认“问题”视图(通常显示编译错误/警告)仍然会显示类似于 无法找到工件< /code> 和 systemPath 应该是绝对路径,但为 ${env.MY_ENV_VARIABLE}/the_local_jar_archive.jar

我如何修复它

进入窗口 ->首选项->一般->工作空间->链接资源并定义一个新的路径变量。

我的例子中,我只需要右键单击我的 pom.xml 文件,选择 Maven ->更新项目,错误从“问题”视图中消失。

I was trying to achieve this but in the context of a MAVEN build. As part of my pom.xml configuration, I had a reference to an environment variable as part of a path to a local JAR:

<dependency>
  <groupId>the group id</groupId>
  <artifactId>the artifact id</artifactId>
  <version>the version</version>
  <scope>system</scope>
    <systemPath>${env.MY_ENV_VARIABLE}/the_local_jar_archive.jar</systemPath>
</dependency>

To compile my project, I had to define the environment variable as part of the run configuration for the maven build as explained by Max's answer. I was able to launch the maven compilation and the project would compile just fine.

However, as this environment variable involves some dependencies, the default "problems" view of Eclipse (where compilation errors/warnings usually show) would still show errors along the lines of Could not find artifact and systemPath should be an absolute path but is ${env.MY_ENV_VARIABLE}/the_local_jar_archive.jar.

How I fixed it

Go into Window -> Preferences -> General -> Worksapce -> Linked Resources and define a new path variable.

image capture of the Eclipse Preferences window

Finally, in my case I just needed to Right click on my pom.xml file, select Maven -> Update Project and the errors disappeared from the "Problems" view.

恬淡成诗 2024-12-06 03:49:02

对于想要在Eclipse项目中覆盖操作系统环境变量的人,也可以参考@MAX答案。

当您在同一台计算机上发布项目结束 Eclipse 项目时,它非常有用。

发布项目可以使用操作系统环境变量进行测试使用,而 eclipse 项目可以覆盖它以供开发使用。

For the people who want to override the Environment Variable of OS in Eclipse project, refer to @MAX answer too.

It's useful when you have release project end eclipse project at the same machine.

The release project can use the OS Environment Variable for test usage and eclipse project can override it for development usage.

陪你到最终 2024-12-06 03:49:02

我能够设置环境。变量通过获取(shell (ksh) scirpt 内的 source 命令)设置它们的文件来实现。
然后我从外部工具调用 .ksh 脚本

I was able to set the env. variables by sourcing (source command inside the shell (ksh) scirpt) the file that was settign them.
Then I called the .ksh script from the external Tools

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文