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

查看:32
本文介绍了设置环境变量启动 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).

包装eclipse的bash脚本:

bash script wrapping eclipse:

我创建了一个名为eclipse.command 设置环境然后启动eclipse.这也会打开一个终端窗口作为日食图标并允许人们为了保持码头"光秃秃的日食.我不能放坞站上的 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 应用程序时,有一个替代的解决方案是用一个设置环境的 shell 包装器替换 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天全站免登陆