简体   繁体   English

如何使用 Eclipse 创建通用启动配置?

[英]How to create a generic launch configuration with Eclipse?

I have a run configuration in my eclipse.我的 eclipse 中有一个运行配置。 In my project we have two branches : DEV and STABLE.在我的项目中,我们有两个分支:DEV 和 STABLE。 I would like to create one run configuration for building my project whatever branch it is on.我想创建一个运行配置来构建我的项目,无论它位于哪个分支。

For now, when I set Base directory with one of those two variables : ${project_path} , ${build_project} , I face this error :现在,当我使用这两个变量之一设置Base directory时: ${project_path}${build_project} ,我面临这个错误:

Base directory doesn't exist or can't be read.基目录不存在或无法读取。

This works : ${workspace_loc:/my-project-dev-branch} but is tied to a particular branch.这有效: ${workspace_loc:/my-project-dev-branch}但绑定到特定分支。 I must duplicate this configuration for building the stable branch.我必须复制这个配置来构建稳定的分支。

  • So, how can I view the actual content of ${project_path} , ${build_project} ?那么,如何查看${project_path}${build_project}的实际内容?
  • Or which variable should I use to get this result : ${workspace_loc:/${eclipse_variable_with_project_name}} ?或者我应该使用哪个变量来获得这个结果: ${workspace_loc:/${eclipse_variable_with_project_name}}

I'm not sure I follow how your branches are represented within the workspace, but我不确定我是否遵循您的分支在工作区中的表示方式,但是

  • ${project_path} represents a path relative to your workspace ${project_path}表示相对于您的工作区的路径
  • ${build_project} will only be set during an actual build (not during an execution of your program) ${build_project}只会在实际构建期间设置(而不是在程序执行期间)

Based on your description you want to be using ${project_loc} instead.根据您的描述,您希望改用${project_loc}

Nota: The project MUST be selected in the perspective project before launching the run configuration.注意:在启动运行配置之前,必须在透视项目中选择该项目。 Otherwise, you will get a message like in the screenshot below :否则,您将收到如下屏幕截图所示的消息:

带有文本“启动我的运行配置”的警告框弹出图片遇到问题。变量引用空选择:${project_loc}'

As you are already creating a String Substitution variable, through Run Debug->String Substitution in Eclipse Preferences, to deal with separate paths, you could either:由于您已经创建了一个字符串替换变量,通过在 Eclipse 首选项中运行调试->字符串替换来处理单独的路径,您可以:

  1. Create a variable, eg branch_loc , with a value of ${workspace_loc:/my-project-dev-branch}创建一个变量,例如branch_loc ,值为${workspace_loc:/my-project-dev-branch}
  2. If the paths only differ slightly, eg by branch name, then you could create a variable branch with a value, eg dev , and then create branch_loc with ${workspace_loc}\\${branch}如果路径仅略有不同,例如通过分支名称,那么您可以创建一个带有值的变量branch ,例如dev ,然后使用${workspace_loc}\\${branch}创建branch_loc

Then use ${branch_loc} for you Maven base directory.然后将${branch_loc}用于您的 Maven 基本目录。

It would be better to have all branches use the same path, which git and mercurial allow you to do.最好让所有分支使用相同的路径,git 和 mercurial 允许您这样做。 Then you could use ${project_loc} for your Maven base directory.然后您可以将${project_loc}用于您的 Maven 基本目录。 For project_loc if you specify the project name of your project, eg ${project_loc:MY_PROJECT_NAME} , then it doesn't require you to select the project in order to work.对于project_loc如果您指定项目的项目名称,例如${project_loc:MY_PROJECT_NAME} ,那么它不需要您选择项目即可工作。

If you right click on the project and then select Properties, you can see what ${project_path} will resolve to by looking at path and what ${project_loc} will resolve to by looking at location.如果您右键单击该项目,然后选择“属性”,您可以通过查看路径来查看${project_path}将解析为什么,以及通过查看位置来查看${project_loc}将解析为什么。

First of all, if you are using git as version control system: Do not checkout the project twice, but just switch between branches in a single project.首先,如果您使用 git 作为版本控制系统:不要两次检出项目,而只是在单个项目中的分支之间切换。 Git was designed for that and can do that in seconds. Git 就是为此而设计的,并且可以在几秒钟内完成。 That way your problem would vanish completely.这样你的问题就会完全消失。

If that is not an option, maybe putting the run configuration under version control itself would be an alternative.如果这不是一个选项,也许将运行配置置于版本控制之下将是另一种选择。 Set the Shared file option as shown with the first highlight:设置共享文件选项,如第一个突出显示所示:在此处输入图片说明

Then you can run the run configuration by selecting it in the respective project (as that is really a file there) and launch it via context menu.然后您可以通过在相应的项目中选择它来运行运行配置(因为它实际上是那里的一个文件)并通过上下文菜单启动它。 However, I've never tried this with the same launch configuration checked out twice.但是,我从未尝试过两次检查相同的启动配置。

You can set the base directory in below mentioned way:您可以通过下面提到的方式设置基本目录:

${project_loc:${project_name}}

You can find the above variables from the variables option.您可以从变量选项中找到上述变量。

Also you can set your mvn command in goals as example below:您也可以在目标中设置您的 mvn 命令,如下例所示:

clean install -PautoInstallPackage -Padobe-public -DskipTests

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

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