简体   繁体   English

在Mac上的Eclipse中为Maven设置通用环境变量

[英]Setting universal Environment variables for Maven in Eclipse on Mac

I have a large number of Maven projects that all depend on certain environment variables. 我有大量的Maven项目,它们都依赖于某些环境变量。 They are the same ones for all projects. 对于所有项目,它们都是相同的。 I am aware that I can create a run configuration for a given project, but I want to basically have the run configuration work for all my projects without having to set it up specifically. 我知道我可以为给定项目创建运行配置,但是我希望基本上可以为所有项目运行运行配置,而不必专门进行设置。

I am open to having Eclipse either read from my .bash_profile, or loading them in a different way. 我愿意让Eclipse从我的.bash_profile中读取,或者以其他方式加载它们。

If it's OK to have multiple maven launch configurations, just setup the first configuration and create the others as copies, so you don't have to enter common information over and over. 如果可以使用多个Maven启动配置,则只需设置第一个配置并将其他配置创建为副本,这样就不必一遍又一遍地输入常用信息。

If you need the flexibility to later change those environment variables (without having to edit many locations), try the following: 如果您需要以后更改这些环境变量的灵活性(而不必编辑许多位置),请尝试以下操作:

First go to Preferences > Run/Debug > String Substitution and create one or more new "variables" (name x value x description), eg, name = myVar, value = 13 首先转到Preferences > Run/Debug > String Substitution并创建一个或多个新的“变量”(名称x值x描述),例如,名称= myVar,值= 13

Then in a m2e launch configuration ( Run As ... > Maven Build ... ) in the Environment tab define environment variables using the variables from step 1 as their values, eg, name = myEnvVar, value = ${myVar}. 然后,在“ Environment选项卡中的m2e启动配置( Run As ... > Maven Build ... )中,使用步骤1中的变量作为值来定义环境变量,例如name = myEnvVar,value = $ {myVar}。 This should pass an environment variable myEnvVar=13 into your maven build. 这应该将环境变量myEnvVar = 13传递到您的Maven构建中。

Instead of typing ${myVar} you can also click on Variables... while editing the environment variable and select your variable from the list. 除了输入$ {myVar},您还可以在编辑环境变量时单击Variables... ,然后从列表中选择变量。

Now changing the variable from step 1 (myVar) will affect all your launch configurations which refer to it. 现在,从步骤1(myVar)更改变量将影响引用该变量的所有启动配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM