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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15762751/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 20:19:03  来源:igfitidea点击:

How to create a generic launch configuration with Eclipse?

javaeclipsemavenrun-configurationlaunch-configuration

提问by Stephan

I have a run configuration in my eclipse. In my project we have two branches : DEV and STABLE. I would like to create one run configuration for building my project whatever branch it is on.

我的 eclipse 中有一个运行配置。在我的项目中,我们有两个分支:DEV 和 STABLE。我想创建一个运行配置来构建我的项目,无论它位于哪个分支。

For now, when I set Base directorywith 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. I must duplicate this configuration for building the stable branch.

这有效:${workspace_loc:/my-project-dev-branch}但与特定分支相关联。我必须复制这个配置来构建稳定的分支。

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

回答by Perception

I'm not sure I follow how your branches are represented within the workspace, but

我不确定我是否遵循您的分支在工作区中的表示方式,但是

  • ${project_path}represents a path relative to your workspace
  • ${build_project}will only be set during an actual build (not during an execution of your program)
  • ${project_path}表示相对于您的工作区的路径
  • ${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 :

注意:在启动运行配置之前,必须在透视项目中选择该项目。否则,您将收到如下屏幕截图所示的消息:

picture of Alert box popup with the text 'Launching MY RUN CONFIGURATION' has encountered a problem.  Variable references empty selection: ${project_loc}'

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

回答by WhiteKnight

As you are already creating a String Substitutionvariable, through Run Debug->String Substitution in Eclipse Preferences, to deal with separate paths, you could either:

由于您已经创建了一个字符串替换变量,通过在 Eclipse 首选项中运行调试->字符串替换来处理单独的路径,您可以:

  1. Create a variable, e.g. branch_loc, with a value of ${workspace_loc:/my-project-dev-branch}
  2. If the paths only differ slightly, e.g. by branch name, then you could create a variable branchwith a value, e.g. dev, and then create branch_locwith ${workspace_loc}\${branch}
  1. 创建一个变量,例如branch_loc,值为${workspace_loc:/my-project-dev-branch}
  2. 如果路径只能通过分支名称略有下降,如不同,那么你可以创建一个变量branch与值,例如dev,然后创建branch_loc${workspace_loc}\${branch}

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. Then you could use ${project_loc}for your Maven base directory. For project_locif you specify the project name of your project, e.g. ${project_loc:MY_PROJECT_NAME}, then it doesn't require you to select the project in order to work.

最好让所有分支使用相同的路径,git 和 mercurial 允许您这样做。然后你可以使用${project_loc}你的 Maven 基目录。因为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}通过查看位置将解析为什么。

回答by Bananeweizen

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 was designed for that and can do that in seconds. That way your problem would vanish completely.

首先,如果你使用 git 作为版本控制系统:不要两次 checkout 项目,而只是在单个项目的分支之间切换。Git 就是为此而设计的,并且可以在几秒钟内完成。这样你的问题就会完全消失。

If that is not an option, maybe putting the run configuration under version control itself would be an alternative. Set the Shared fileoption as shown with the first highlight: enter image description here

如果这不是一个选项,也许将运行配置置于版本控制之下将是另一种选择。设置共享文件选项,如第一个突出显示所示: 在此处输入图片说明

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 samelaunch configuration checked out twice.

然后您可以通过在相应的项目中选择它来运行运行配置(因为它实际上是那里的一个文件)并通过上下文菜单启动它。但是,我从未尝试过两次检查相同的启动配置。