启动 mac eclipse 并设置环境变量 [英] Launch mac eclipse with environment variables set

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

问题描述

我公司提供了一个基于 Eclipse 的开发环境,需要为底层工具链设置一些环境变量,以便可以同时安装多个版本而不会接管系统.

My company provides an eclipse based development environment which needs some environment variables setting up for the underlying toolchain so multiple versions can be installed concurrently and not take over the system.

我想在 finder 或 Dock 中提供一个图标,设置这些图标然后启动 eclipse,这样客户就不会在没有设置环境的情况下意外启动 eclipse.这是我迄今为止尝试过的:

I want to provide an icon in finder or the dock which sets these then launches eclipse so customers cannot accidentally launch eclipse without the environment being set. This is what I have tried so far:

  1. 在Info.plist中设置环境日食:

  1. Setting environment in Info.plist for eclipse:

这应该是一个很好的方法但我不能让它添加到现有路径(如导出PATH=/myapp/bin:$PATH).

This should be a nice way to do it but I cannot make it add to the existing path (like export PATH=/myapp/bin:$PATH).

bash 脚本包装日食:

bash script wrapping eclipse:

我创建了一个名为的 bash 脚本eclipse.command 来设置环境然后启动eclipse.这也会打开一个终端窗口作为日食图标并允许人们留在码头"为裸蚀.我不能放Dock 上的 eclipse.command 原样不是应用程序.

I created a bash script called eclipse.command to set the environment then launch eclipse. This opens a terminal window as well as the eclipse icon and allows people to "Keep on dock" for the bare eclipse. I cannot put eclipse.command on the dock as it is not an application.

Applescript 包装 eclipse.command:

Applescript wrapping eclipse.command:

Applescript 包装器eclipse.command 使它看起来像一个应用程序并阻止终端窗口出现.不幸的是,我现在获得一个停靠栏图标applescript 和一个用于 eclipse 所以仍然可以保持赤裸裸的日食码头.

An Applescript wrapper around eclipse.command makes it look like an app and prevents the terminal window appearing. Unfortunately I now get a dock icon for the applescript and one for eclipse so can still keep the bare eclipse on the dock.

有什么建议吗?我是否以完全错误的方式处理这个问题?

Any suggestions? Am I going about this in completely the wrong way?

推荐答案

有一种替代解决方案,它涉及在用户启动 Eclipse 应用程序时替换由 MacOS X 运行的可执行文件,使用一个用于设置环境的外壳包装器.

There is an alternate solution which involves replacing the executable that is run by MacOS X when the user launches the Eclipse application with a shell wrapper that sets up the environment.

在 Eclipse 应用程序包目录/Applications/eclipse/Eclipse.app/Contents/MacOS 中创建一个名为eclipse.sh"的空文本文件.

Create an empty text file called "eclipse.sh" in the Eclipse application bundle directory /Applications/eclipse/Eclipse.app/Contents/MacOS.

在文本编辑器中打开eclipse.sh并输入以下内容:

Open the eclipse.sh in a text editor an enter the following contents:

#!/bin/sh

export ENV_VAR1=value
export ENV_VAR2=value

logger "`dirname "$0"`/eclipse"

exec "`dirname "$0"`/eclipse" $@

在示例中 ENV_VAR1 和 ENV_VAR2 是正在设置的环境变量.这些变量对从 Eclipse 内启动的进程可见.logger 命令只会将 eclipse 可执行文件的路径记录到 system.log 作为调试帮助.

In the example ENV_VAR1 and ENV_VAR2 are the environment variables being set up. These variables will be visible to processes launched from within Eclipse. The logger command will just log the path of the eclipse executable to the system.log as a debugging aid.

在终端设置shell脚本eclipse.sh的可执行标志,即:

In the Terminal set the executable flag of the shell script eclipse.sh, i.e.:

chmod +x /Applications/eclipse/Eclipse.app/Contents/MacOS/eclipse.sh

打开 Eclipse.app Info.plist 并将键 CFBundleExecutable 的值从 eclipse 更改为 eclipse.sh.

Open the Eclipse.app Info.plist and change the value for the key CFBundleExecutable from eclipse to eclipse.sh.

MacOS X 不会自动检测到 Eclipse.app 的 Info.plist 已更改.因此,您需要使用 lsregister 命令强制更新终端中的 LaunchService 数据库:

MacOS X does not automatically detect that the Eclipse.app's Info.plist has changed. Therefore you need to force update the LaunchService database in the Terminal by using the lsregister command:

/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -v -f /Applications/eclipse/Eclipse.app

下次从 Dock 或 Finder 启动 Eclipse.app 时,应设置环境变量.

The next time you launch Eclipse.app from the Dock or from the Finder the environment variables should be set.

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

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