简体   繁体   English

配置Eclipse以使用Javascript编辑器

[英]Configure Eclipse to use Javascript editor

When editing JSPs in Eclipse, the contents of <script> tags - ie Javascript code - is properly color coded and formated. 在Eclipse中编辑JSP时, <script>标记的内容 - 即Javascript代码 - 被正确地进行颜色编码和格式化。

For reasons that go beyond the scope of this question, I have created a custom javascript tag, let's call it <sj:script> . 出于超出此问题范围的原因,我创建了一个自定义的javascript标记,我们称之为<sj:script> The body of this type is pure javascript as you would have in a regular <script> tag. 这种类型的主体是纯javascript,就像你在常规的<script>标签中一样。

However, when I have Javascript code within my custom tag, it is treated as simple text (no color coding, no proper indentation, etc). 但是,当我在自定义标记中包含Javascript代码时,它被视为简单文本(没有颜色编码,没有适当的缩进等)。

My question is, how do I make Eclipse use a specific editor within custom JSP tags? 我的问题是,如何让Eclipse在自定义JSP标记中使用特定的编辑器?

You can try MyEclipse or Aptana Studio . 您可以尝试MyEclipseAptana Studio They offer much better editors for web development. 它们为Web开发提供了更好的编辑器。

But a much better approach is to put the JS into a different file and reference that with <script src="..."> : 但更好的方法是将JS放入不同的文件中并使用<script src="...">引用它:

  1. You can use a better editor 你可以使用更好的编辑器
  2. The browser can cache the JavaScript (instead of downloading it every time with the rest of the page) 浏览器可以缓存JavaScript(而不是每次都与页面的其余部分一起下载)
  3. You can write tests for the JavaScript (next to impossible when the JS is held hostage in a JSP file). 您可以为JavaScript编写测试(当JS在JSP文件中保存时,几乎不可能)。

[EDIT] Eclipse is open source. [编辑] Eclipse是开源的。 Download the code for the WTP project, look for the text editor parts and search for "script". 下载WTP项目的代码,查找文本编辑器部分并搜索“脚本”。 In all places that you find, add "sj:script", too. 在您找到的所有地方,也添加“sj:script”。

您是否在使用自定义标记的jsp中包含了标记库描述符文件?

I have a list of plugins for eclipse which enable eclipse to edit JS files: 我有一个eclipse插件列表,它使eclipse能够编辑JS文件:

http://www.delicious.com/powtac/javascript+eclipse http://www.delicious.com/powtac/javascript+eclipse

Just go trough the links and see the different descriptions how to install them. 只需通过链接,看到不同的描述如何安装它们。

AFAIK, editors are chosen based on file extension, and there's no mechanism to customize this based on particular content inside the file. AFAIK,编辑器是根据文件扩展名选择的,没有机制根据文件中的特定内容对其进行自定义。

I see 2 options 我看到2个选项

  • Creating a custom text editor to take into account your custom script tag (probably not worth the effort) 创建自定义文本编辑器以考虑您的自定义脚本标记(可能不值得付出努力)
  • Put your javascript snippet in an external file, use the include directive inside your custom script tag. 将您的javascript代码段放在外部文件中,在自定义脚本代码中使用include指令。

      <%@ include file="javascript.js" %> 

Eclipse has a template feature where in you can add specific tag ,which can be made available for all JSP pages. Eclipse具有模板功能,您可以在其中添加特定标记,该标记可用于所有JSP页面。

Ensure you have installed Eclipse WTP ( Web Tools Platform ) 确保已安装Eclipse WTP(Web Tools Platform)

1.Open Preferences window [ Select Window > Preferences ] 2.Expand Web Option from the menu, upon which you can see [ CSS Files,HTML Files etc.. 3.Select JSP Files 4.Select Editor 5.Select Templates 6.In the corresponding pane , click New and from there rest can be easily done. 1.打开首选项窗口[选择窗口>首选项] 2.从菜单中展开Web选项,您可以在其中看到[CSS文件,HTML文件等.3。选择JSP文件4.选择编辑器5.选择模板6.In在相应的窗格中,单击“新建”,然后可以轻松完成其余操作。

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

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