Tuesday, August 20, 2013

Eliminating JavaScript validation errors due to jQuery in an Eclipse dynamic web project

If your Eclipse project includes jQuery files such as jquery-1.8.3.min.js, Eclipse's JavaScript validation may report syntax errors that, although harmless, makes it look as  if your project contains bugs.



Much has been written online about how to resolve this problem, but not all of it is correct. In particular, suggestions involving Properties | Validation | Client-side JavaScript are off the mark, as these settings affect JavaScript within  HTML pages, not standalone .js files.

This comment -- https://bugs.eclipse.org/bugs/show_bug.cgi?id=349020#c15 -- has it right but doesn't give much detail. Here are the exact steps I followed to correct the problem:

1. Right-click the project name in Project Explorer and select Properties.

2. Expand JavaScript and select Include Path.


3. Expand the folder that contains the offending JavaScript files (which will vary depending on how you've set up your project), and click Excluded.


4. Click Edit. Click the Add button next to the Exclusion patterns textarea.


5. Now type in the pattern for files to be excluded, being careful to include the correct path, which will vary depending on how you've set up your project. In my project, the pattern is resources\lib\jquery*.*.


6. Click OK. Click Finish. Click OK. The errors should now disappear.


Behind the scenes, this added the following line to my project's .settings\.jsdtscope file:
<classpathentry excluding="resources/lib/jquery*.*" kind="src" path="src/main/webapp"/>

Resolving the error "Java compiler level does not match the version of the installed Java project" in Eclipse

I inherited a Java project created by another developer. When I opened it in Eclipse, I was able to build and run it, but Eclipse's Problems window showed an error, "Java compiler level does not match the version of the installed Java project."


Here's how I fixed it:

1. Right-click the project name in Project Explorer and select Properties. Then click Project Facets.
 
 
2. Click the dropdown arrow to the right of Java. Select the value 1.6, rather than 1.5.
 
 
3. Click OK. The error should disappear from the Problems window.