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

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

问题描述

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



我想在finder或dock中提供一个图标,然后设置它们,然后启动eclipse,以便客户不会在环境设置的情况下不小心启动eclipse。这是我迄今为止所尝试的:


  1. 设置环境在Info.plist
    中为eclipse:



    这应该是一个很好的方式来做
    但是我不能添加到
    现有路径(如export
    PATH = / myapp / bin:$ PATH)


  2. bash脚本包装eclipse:



    我创建了一个bash脚本称为
    eclipse.command设置
    环境然后启动eclipse。
    这将打开一个终端窗口以及
    作为eclipse图标,并允许
    个人$ on $ on $
    裸食。我不能把
    eclipse.command放在码头上,因为它是
    不是一个应用程序。


  3. 苹果脚本包装eclipse.command: p>

    围绕
    eclipse.command的Applescript包装器使其看起来像
    一个应用程序,并防止终端
    窗口出现。不幸的是,我
    现在得到
    applescript的Dock图标,一个用于eclipse,所以
    仍然可以将裸机保持在
    底座上。


任何建议?我是以完全错误的方式进行的吗?

解决方案

有一个替代解决方案,其中涉及到替换由当用户使用设置环境的外壳程序启动Eclipse应用程序时,MacOS X。



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



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

 #!/ 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中作为调试帮助。



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

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

打开Eclipse.app Info.plist并将关键字CFBundleExecutable的值从eclipse更改为eclipse.sh。 / p>

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

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

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


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.

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. Setting environment in Info.plist for eclipse:

    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).

  2. bash script wrapping eclipse:

    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.

  3. Applescript wrapping eclipse.command:

    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?

解决方案

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.

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

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" $@

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.

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

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

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

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天全站免登陆