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.
我的公司提供了一个基于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:
我想在finder或dock中提供一个图标,然后设置这些图标然后启动eclipse,这样客户就不会在没有设置环境的情况下意外启动eclipse。这是我到目前为止所尝试的:
-
Setting environment in Info.plist for eclipse:
在Info.plist中为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).
这应该是一个很好的方法,但我不能使它添加到现有的路径(如导出PATH = / myapp / bin:$ PATH)。
-
bash script wrapping eclipse:
包装eclipse的bash脚本:
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.
我创建了一个名为eclipse.command的bash脚本来设置环境然后启动eclipse。这将打开一个终端窗口以及eclipse图标,并允许人们为“日食”“保持停靠”。我不能把eclipse.command放在Dock上,因为它不是一个应用程序。
-
Applescript wrapping eclipse.command:
Applescript包装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.
eclipse.command附近的Applescript包装使它看起来像一个应用程序,并阻止终端窗口出现。不幸的是,我现在得到了一个苹果脚的停靠图标和一个用于日食的停靠图标,所以仍然可以保持码头上的日蚀。
Any suggestions? Am I going about this in completely the wrong way?
有什么建议?我是以完全错误的方式解决这个问题吗?
8 个解决方案
#1
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.
有一个替代解决方案涉及在用户使用设置环境的shell包装器启动Eclipse应用程序时替换MacOS X运行的可执行文件。
Create an empty text file called "eclipse.sh" in the Eclipse application bundle directory /Applications/eclipse/Eclipse.app/Contents/MacOS.
在Eclipse应用程序包目录/Applications/eclipse/Eclipse.app/Contents/MacOS中创建一个名为“eclipse.sh”的空文本文件。
Open the eclipse.sh in a text editor an enter the following contents:
在文本编辑器中打开eclipse.sh,输入以下内容:
#!/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.
在示例中,ENV_VAR1和ENV_VAR2是正在设置的环境变量。从Eclipse中启动的进程可以看到这些变量。 logger命令只是将eclipse可执行文件的路径记录到system.log作为调试帮助。
In the Terminal set the executable flag of the shell script eclipse.sh, i.e.:
在终端中设置shell脚本eclipse.sh的可执行标志,即:
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.
打开Eclipse.app Info.plist并将密钥CFBundleExecutable的值从eclipse更改为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:
MacOS X不会自动检测到Eclipse.app的Info.plist已更改。因此,您需要使用lsregister命令强制更新终端中的LaunchService数据库:
/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.
下次从Dock或Finder启动Eclipse.app时,应设置环境变量。
#2
I created the following:
我创建了以下内容:
alias start-eclipse='open /Applications/eclipse/Eclipse.app'
别名start-eclipse ='open /Applications/eclipse/Eclipse.app'
If you run start-eclipse from the command line, all env vars will be picked up. This way, you only need to maintain a single set of env vars across both command-line and eclipse environments.
如果从命令行运行start-eclipse,将会拾取所有env变量。这样,您只需要在命令行和eclipse环境中维护一组env变量。
#3
Take a look at a related question: Environment variables in Mac OS X.
看一下相关问题:Mac OS X中的环境变量。
Basically, this involves the creation of a ~/.MacOSX/environment.plist
file.
基本上,这涉及创建〜/ .MacOSX / environment.plist文件。
Log out and Log in for the environment.plist to get picked up by .App's
注销并登录environment.plist以获取.App的
#4
sakra's answer above is awesome, except is doesn't automatically inherit your existing bash environment. To ensure eclipse.sh picks up your existing bash environment, modify eclipse.sh to use bash instead of sh and add a line to source your existing ~/.bash_profile thus:
sakra的答案很棒,除了不会自动继承你现有的bash环境。为了确保eclipse.sh选择你现有的bash环境,修改eclipse.sh以使用bash而不是sh并添加一行来源你现有的〜/ .bash_profile:
#!/bin/bash
source ~/.bash_profile
logger "`dirname \"$0\"`/eclipse"
exec "`dirname \"$0\"`/eclipse" $@
#5
This worked perfectly in OS X Yosemite:
这在OS X Yosemite中完美运行:
- Open /Applications/Automator.
- When the drop-down appears asking you what kind of document you want to create, choose "Application."
- In the second-from-the-left list, double-click "Run Shell Script."
-
In the right side delete the "cat" that gets put there automatically, and replace it with this:
在右侧删除自动放置的“cat”,并将其替换为:
source ~/.bash_profile && /Applications/eclipse/Eclipse.app/Contents/MacOS/eclipse
当出现下拉菜单询问您要创建哪种文档时,请选择“应用程序”。
在左起第二个列表中,双击“运行Shell脚本”。
Now go to File->Save, and save the application to your Applications directory. I named it "Eclipse" with a capital 'E' so as not to conflict with the "eclipse" directory I already had. For good measure, you can even give it the Eclipse icon by selecting the real eclipse app, pressing command-i, selecting the icon, pressing command-c, then selecting the automator "Eclipse" app, pressing command-i, selecting the icon, and pressing command-v.
现在转到File-> Save,将应用程序保存到Applications目录。我用资本'E'命名为“Eclipse”,以免与我已经拥有的“eclipse”目录冲突。通过选择真实的eclipse应用程序,按下命令-i,选择图标,按下命令-c,然后选择自动“Eclipse”应用程序,按下命令-i,选择图标,您甚至可以给它Eclipse图标。 ,并按下命令-v。
Now you can open the app, or even drag it to your dock. Note that if you start it, the "real" eclipse will still show up in your dock as a separate icon, but you can't have everything. :)
现在您可以打开应用程序,甚至可以将其拖到停靠栏中。请注意,如果你启动它,“真正的”日食仍将作为一个单独的图标显示在你的Dock中,但你不能拥有一切。 :)
#6
None of the above worked for me. you have to set Eclipse -> Preferences -> Terminal -> Arguments set to --login That will instruct Eclipse to login with your account just after opening Terminal.
以上都不适合我。你必须设置Eclipse - > Preferences - > Terminal - > Arguments设置为--login这将指示Eclipse在打开终端后立即使用您的帐户登录。
See screenshot:
Reference: https://marketplace.eclipse.org/comment/4259#comment-4259
#7
Link to Eclipse doesn't use the path set in .bashrc
链接到Eclipse不使用.bashrc中设置的路径
- Create simple script
创建简单的脚本
#!/bin/bash source /home/user/.environment_variables /home/user/eclipse_cpp/eclipse -Duser.name="My Name"
2. Next put your all system variables in file /home/user/.environment_variables (any file you want)
2.接下来将所有系统变量放入文件/home/user/.environment_variables(您想要的任何文件)
My looks like:
我看起来像:
export COCOS_ROOT=/home/user/Projects/edukoala
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/
3. Now you can delete your variables in .bashrc and put line
3.现在您可以删除.bashrc中的变量并放入行
source /home/user/.environment_variables
Everything works fine :)
一切正常:)
#8
As pointed out in https://github.com/atom/atom/issues/7045, the environment variables can be loaded automatically, without explicit source ~/.bash_profile
by using
正如https://github.com/atom/atom/issues/7045中所指出的,环境变量可以自动加载,没有明确的源〜/ .bash_profile使用
#!/usr/bin/env bash -l
instead of
#!/bin/bash
source ~/.bash_profile
after that, in both cases, follows
之后,在这两种情况下,如下
exec "`dirname \"$0\"`/eclipse" $@
It works great for me, thanks for all previous work.
它对我很有用,感谢以前的所有工作。
#1
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.
有一个替代解决方案涉及在用户使用设置环境的shell包装器启动Eclipse应用程序时替换MacOS X运行的可执行文件。
Create an empty text file called "eclipse.sh" in the Eclipse application bundle directory /Applications/eclipse/Eclipse.app/Contents/MacOS.
在Eclipse应用程序包目录/Applications/eclipse/Eclipse.app/Contents/MacOS中创建一个名为“eclipse.sh”的空文本文件。
Open the eclipse.sh in a text editor an enter the following contents:
在文本编辑器中打开eclipse.sh,输入以下内容:
#!/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.
在示例中,ENV_VAR1和ENV_VAR2是正在设置的环境变量。从Eclipse中启动的进程可以看到这些变量。 logger命令只是将eclipse可执行文件的路径记录到system.log作为调试帮助。
In the Terminal set the executable flag of the shell script eclipse.sh, i.e.:
在终端中设置shell脚本eclipse.sh的可执行标志,即:
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.
打开Eclipse.app Info.plist并将密钥CFBundleExecutable的值从eclipse更改为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:
MacOS X不会自动检测到Eclipse.app的Info.plist已更改。因此,您需要使用lsregister命令强制更新终端中的LaunchService数据库:
/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.
下次从Dock或Finder启动Eclipse.app时,应设置环境变量。
#2
I created the following:
我创建了以下内容:
alias start-eclipse='open /Applications/eclipse/Eclipse.app'
别名start-eclipse ='open /Applications/eclipse/Eclipse.app'
If you run start-eclipse from the command line, all env vars will be picked up. This way, you only need to maintain a single set of env vars across both command-line and eclipse environments.
如果从命令行运行start-eclipse,将会拾取所有env变量。这样,您只需要在命令行和eclipse环境中维护一组env变量。
#3
Take a look at a related question: Environment variables in Mac OS X.
看一下相关问题:Mac OS X中的环境变量。
Basically, this involves the creation of a ~/.MacOSX/environment.plist
file.
基本上,这涉及创建〜/ .MacOSX / environment.plist文件。
Log out and Log in for the environment.plist to get picked up by .App's
注销并登录environment.plist以获取.App的
#4
sakra's answer above is awesome, except is doesn't automatically inherit your existing bash environment. To ensure eclipse.sh picks up your existing bash environment, modify eclipse.sh to use bash instead of sh and add a line to source your existing ~/.bash_profile thus:
sakra的答案很棒,除了不会自动继承你现有的bash环境。为了确保eclipse.sh选择你现有的bash环境,修改eclipse.sh以使用bash而不是sh并添加一行来源你现有的〜/ .bash_profile:
#!/bin/bash
source ~/.bash_profile
logger "`dirname \"$0\"`/eclipse"
exec "`dirname \"$0\"`/eclipse" $@
#5
This worked perfectly in OS X Yosemite:
这在OS X Yosemite中完美运行:
- Open /Applications/Automator.
- When the drop-down appears asking you what kind of document you want to create, choose "Application."
- In the second-from-the-left list, double-click "Run Shell Script."
-
In the right side delete the "cat" that gets put there automatically, and replace it with this:
在右侧删除自动放置的“cat”,并将其替换为:
source ~/.bash_profile && /Applications/eclipse/Eclipse.app/Contents/MacOS/eclipse
当出现下拉菜单询问您要创建哪种文档时,请选择“应用程序”。
在左起第二个列表中,双击“运行Shell脚本”。
Now go to File->Save, and save the application to your Applications directory. I named it "Eclipse" with a capital 'E' so as not to conflict with the "eclipse" directory I already had. For good measure, you can even give it the Eclipse icon by selecting the real eclipse app, pressing command-i, selecting the icon, pressing command-c, then selecting the automator "Eclipse" app, pressing command-i, selecting the icon, and pressing command-v.
现在转到File-> Save,将应用程序保存到Applications目录。我用资本'E'命名为“Eclipse”,以免与我已经拥有的“eclipse”目录冲突。通过选择真实的eclipse应用程序,按下命令-i,选择图标,按下命令-c,然后选择自动“Eclipse”应用程序,按下命令-i,选择图标,您甚至可以给它Eclipse图标。 ,并按下命令-v。
Now you can open the app, or even drag it to your dock. Note that if you start it, the "real" eclipse will still show up in your dock as a separate icon, but you can't have everything. :)
现在您可以打开应用程序,甚至可以将其拖到停靠栏中。请注意,如果你启动它,“真正的”日食仍将作为一个单独的图标显示在你的Dock中,但你不能拥有一切。 :)
#6
None of the above worked for me. you have to set Eclipse -> Preferences -> Terminal -> Arguments set to --login That will instruct Eclipse to login with your account just after opening Terminal.
以上都不适合我。你必须设置Eclipse - > Preferences - > Terminal - > Arguments设置为--login这将指示Eclipse在打开终端后立即使用您的帐户登录。
See screenshot:
Reference: https://marketplace.eclipse.org/comment/4259#comment-4259
#7
Link to Eclipse doesn't use the path set in .bashrc
链接到Eclipse不使用.bashrc中设置的路径
- Create simple script
创建简单的脚本
#!/bin/bash source /home/user/.environment_variables /home/user/eclipse_cpp/eclipse -Duser.name="My Name"
2. Next put your all system variables in file /home/user/.environment_variables (any file you want)
2.接下来将所有系统变量放入文件/home/user/.environment_variables(您想要的任何文件)
My looks like:
我看起来像:
export COCOS_ROOT=/home/user/Projects/edukoala
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/
3. Now you can delete your variables in .bashrc and put line
3.现在您可以删除.bashrc中的变量并放入行
source /home/user/.environment_variables
Everything works fine :)
一切正常:)
#8
As pointed out in https://github.com/atom/atom/issues/7045, the environment variables can be loaded automatically, without explicit source ~/.bash_profile
by using
正如https://github.com/atom/atom/issues/7045中所指出的,环境变量可以自动加载,没有明确的源〜/ .bash_profile使用
#!/usr/bin/env bash -l
instead of
#!/bin/bash
source ~/.bash_profile
after that, in both cases, follows
之后,在这两种情况下,如下
exec "`dirname \"$0\"`/eclipse" $@
It works great for me, thanks for all previous work.
它对我很有用,感谢以前的所有工作。