最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Configure Eclipse to use Javascript editor - Stack Overflow

programmeradmin2浏览0评论

When editing JSPs in Eclipse, the contents of <script> tags - i.e. Javascript code - is properly color coded and formated.

For reasons that go beyond the scope of this question, I have created a custom javascript tag, let's call it <sj:script>. The body of this type is pure javascript as you would have in a regular <script> tag.

However, when I have Javascript code within my custom tag, it is treated as simple text (no color coding, no proper indentation, etc).

My question is, how do I make Eclipse use a specific editor within custom JSP tags?

When editing JSPs in Eclipse, the contents of <script> tags - i.e. Javascript code - is properly color coded and formated.

For reasons that go beyond the scope of this question, I have created a custom javascript tag, let's call it <sj:script>. The body of this type is pure javascript as you would have in a regular <script> tag.

However, when I have Javascript code within my custom tag, it is treated as simple text (no color coding, no proper indentation, etc).

My question is, how do I make Eclipse use a specific editor within custom JSP tags?

Share Improve this question edited Dec 1, 2010 at 19:21 jd. asked Nov 24, 2010 at 4:06 jd.jd. 4,0987 gold badges39 silver badges45 bronze badges 3
  • isn't the real question why do you need to define custom tags ? It seems a rather peculiar way to do things. – NimChimpsky Commented Dec 8, 2010 at 16:56
  • It is, I agree. But I'm developing a framework that works in a ... peculiar way – jd. Commented Dec 8, 2010 at 16:59
  • 1 I've ended up in this exact same situation, and am presently looking for an answer. I'll post any findings here if I learn anything. – Jason Sperske Commented Oct 15, 2013 at 21:49
Add a ment  | 

5 Answers 5

Reset to default 1

You can try MyEclipse or Aptana Studio. They offer much better editors for web development.

But a much better approach is to put the JS into a different file and reference that with <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)
  3. You can write tests for the JavaScript (next to impossible when the JS is held hostage in a JSP file).

[EDIT] Eclipse is open source. Download the code for the WTP project, look for the text editor parts and search for "script". In all places that you find, add "sj:script", too.

Have you included the Tag Library Descriptor file in the jsp where you are using the custom tag?

I have a list of plugins for eclipse which enable eclipse to edit JS files:

http://www.delicious./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.

I see 2 options

  • 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.

        <%@ 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.

Ensure you have installed 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.

发布评论

评论列表(0)

  1. 暂无评论