Wednesday, October 27, 2010

JavaScript validation in a Java project with Eclipse's JavaScript developer tools

I'm not sure how may people this applies to, but I ran into the case where some of my web application packages have both Java and JavaScript files.  I use Eclipse, and wanted to be able to take advantage of Eclipse JavaScript Development Tools (JSDT) that provide rich JavaScript functionality within Eclipse. Unfortunately, JavaScript validation (e.g., catching syntax bugs) only occurs by default if you create a "JavaScript" project. Since many of these projects have both Java and JavaScript code, I had to work around this following these steps:
  1. Ensure you have JSDT installed
    • Top Menu -> Eclipse -> About Eclipse -> Installation Details -> Installed Software
  2. Exit Eclipse
  3. Add the org.eclipse.wst.jsdt.core.jsNature:
    • vim $ECLIPSE_PROJECT_ROOT/.project
    • To the natures section, add org.eclipse.wst.jsdt.core.jsNature
  4. Open Eclipse
  5. Enable the preference: JavaScript -> Validator -> Errors/Warnings -> Enable JavaScript semantic validation
    • Adjust the validation preferences as needed.
    • It's usually a good idea to set all of the "Resolution" preferences to ignore
I couldn't find this documented anywhere on the web, so passing it on here in case it's of use.

4 comments:

Paul Beusterien said...

Thanks! This helped me figure out how to make hybrid Java/JavaScript projects work in my plugin for PhoneGap for Android. See http://www.mobiledevelopersolutions.com

Anonymous said...

Thanks, I have exactly this problem, will give it a try!

Phil said...

This worked for me brilliantly - thanks for the suggestion, just what I was looking for!

Aparna said...

Wow, nice post and it is also very informative. Thank you...
Graphic Design Courses in Chennai
graphic design training in chennai
Social Media Marketing Courses in Chennai
Pega Training in Chennai
Primavera Training in Chennai
Unix Training in Chennai
Power BI Training in Chennai
Tableau Training in Chennai
Spark Training in Chennai
Linux Training in Chennai