Eclipse:为 HTML/Javascript 文件设置运行配置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3892862/
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-08-23 06:31:39  来源:igfitidea点击:

Eclipse: Setting up Run Configuration for HTML/Javascript Files

javascripteclipseconfiguration

提问by HalukO

I want to use Eclipse as my editor for HTML/Javascript files. When I "Run", I would like to see a browser (any one of Internet Explorer, Firefox, etc on Windows) launched for my file. How can I set up a 'run configuration' to do this?

我想使用 Eclipse 作为我的 HTML/Javascript 文件编辑器。当我“运行”时,我希望看到为我的文件启动的浏览器(Windows 上的 Internet Explorer、Firefox 等中的任何一种)。如何设置“运行配置”来执行此操作?

回答by Ladlestein

You could set up an External Tool configuration that, when you run it, would open, in a browser, the document you're currently editing. Instead of "Run", you'd click the button next to the Run button, with the little red suitcase over it.

您可以设置一个外部工具配置,当您运行它时,它将在浏览器中打开您当前正在编辑的文档。不是“运行”,而是单击“运行”按钮旁边的按钮,上面有一个红色的小手提箱。

To set it up, use the menus: Run...External Tools...External Tools Configurations. You'll get a configuration dialog. Now:

要设置它,请使用菜单:运行...外部工具...外部工具配置。你会得到一个配置对话框。现在:

  • Give your config a Name (like "view in Firefox")
  • Enter the full path to your browser in the Location field along with the executable name of the browser.
  • Don't worry about the working directory
  • Click the Variables button; in the dialog that pops up, look for the variable called "selected_resource_loc". Choose it and dismiss the popup dialog.
  • And now hit "Apply" and dismiss the main dialog.
  • 为您的配置命名(例如“在 Firefox 中查看”)
  • 在位置字段中输入浏览器的完整路径以及浏览器的可执行文件名称。
  • 不用担心工作目录
  • 单击变量按钮;在弹出的对话框中,查找名为“selected_resource_loc”的变量。选择它并关闭弹出对话框。
  • 现在点击“应用”并关闭主对话框。

Running an External Tool Configuration is a lot like running a Launch Configuration: you can choose from the menus, or use the buttons on the button bar; if you click one of those buttons, it will run the last configuration you selected (on whatever document you're editing).

运行外部工具配置很像运行启动配置:您可以从菜单中进行选择,或使用按钮栏上的按钮;如果您单击其中一个按钮,它将运行您选择的最后一个配置(在您正在编辑的任何文档上)。

The important things to note are:

需要注意的重要事项是:

  • you have to have the right path to the browser executable
  • the arguments to the executable will be those in the Arguments text area, which is where the variable we chose ("selected_resource_loc") will appear; if you need more stuff on that command line, put it in the Arguments
  • the "selected_resource_loc" is expanded at execution time to the full path of the currently-selected document
  • 您必须拥有浏览器可执行文件的正确路径
  • 可执行文件的参数将是参数文本区域中的参数,我们选择的变量(“selected_resource_loc”)将出现在该区域;如果您需要该命令行上的更多内容,请将其放在参数中
  • “selected_resource_loc”在执行时扩展到当前选择的文档的完整路径

See these docsfor more detail.

有关更多详细信息,请参阅这些文档

回答by user3203298

had the same problem, it's really annoying that there is no default behaviour of eclipse to deal with html files.

有同样的问题,eclipse没有处理html文件的默认行为真的很烦人。

here is how i did it with pictures! ;)

这是我用图片做的!;)

http://dwaves.de/index.php/2014/01/16/eclipse-run-launch-html-htm-webpage-in-external-browser-external-tools-shortcut-hotkey/

http://dwaves.de/index.php/2014/01/16/eclipse-run-launch-html-htm-webpage-in-external-browser-external-tools-shortcut-hotkey/

回答by Chandru

I have installed aptana studio plugin for eclipse, and that will enable run as "java script web applicaiton" option.

我已经为 Eclipse 安装了 aptana studio 插件,这将启用作为“java script web applicaiton”选项运行。

Install aptana studio pluging as follows

安装aptana studio插件如下



  1. Open Eclipse
  2. Help -> Install New Software
  3. Add (on the top right)
  4. Enter the following link for Aptana Plugin with
  5. http://download.aptana.com/studio3/plugin/install
  6. Click OK
  7. Put a check mark for Aptana Studio 3
  8. finish
  1. 打开日食
  2. 帮助 -> 安装新软件
  3. 添加(在右上角)
  4. 输入以下 Aptana 插件链接
  5. http://download.aptana.com/studio3/plugin/install
  6. 单击确定
  7. 勾选 Aptana Studio 3
  8. 结束


install wamp server if you dont have it http://www.wampserver.com/

如果你没有,安装 wamp 服务器http://www.wampserver.com/

回答by Jim Blackler

You could install the WTP tools and set up a Static Web Project. Copy your files into that (or you may be able to set up a short cut, I'm not sure). You can change the browser in Preferences->General->Web Browser. Selecting Run with launch the browser and your content.

您可以安装 WTP 工具并设置静态 Web 项目。将您的文件复制到其中(或者您可以设置快捷方式,我不确定)。您可以在 Preferences->General->Web Browser 中更改浏览器。选择 Run with 启动浏览器和您的内容。

Eclipse has great refactoring, syntax checking and formatting now for JavaScript, I really recommend it.

Eclipse 现在对 JavaScript 进行了很好的重构、语法检查和格式化,我真的很推荐它。

回答by user2645333

Go to the Main Menu with in the Select --> window -> webbrowser --> Here by default "internal browser will selcted" if you want to change select --> chrome/firefox/ie then you can run the web application project and the result will be displayed in the web browser you selected.

转到主菜单中的 Select --> window -> webbrowser --> 默认情况下“内部浏览器将选择”如果你想改变选择 --> chrome/firefox/ie 然后你可以运行 web 应用程序项目结果将显示在您选择的网络浏览器中。