How to include the jQuery library in a Spring-MVC Eclipse project

By : Samo

Good day,

I have searched far and wide but all I can find is information about how to add various plugins to Eclipse. I don't want a plugin. I want my stinkin' jQuery!

Some things I've tried:

I download jQuery and put it in my WebContent\WEB-INF\js folder. Then in my WebContent\WEB-INF\jsps\company.jsp file, I have a script tag:

<script type="text/javascript" src="../js/jquery-1.4.3.min.js"></script>

But no dice. So on to the next attempt.

Window -> Preferences -> JavaScript -> Include Path -> User Libraries -> New...

Here I added my jQuery library and referened my file correctly. I can see my jQuery library in JavaScript Resources. It looks just like I'd expect it. But still, my jQuery script is not included in my page.

What am I missing here? Is this such a no-brainer that nobody bothers to properly document how to do this? If it's such a no-brainer, why can't I figure it out? I THOUGHT I had a brain...

By : Samo


You could try using a separate servlet (which I have actually not tried yet) to load up the jQuery.js as static content.

What solved it for me, is putting the jQuery.js file in the /content folder with the rest of html pages, and referencing it relative to root directory for both jsp and html pages.

Why are your JSPs in WEB-INF? They are created in 'WebContent' folder. WEB-INF folder should not be included in the class path.

Don't put your work in WEB-INF folder.

you can also add dependencies of jquery in your pom.xml and include in the script source: <script type="text/javascript" src="webjars/jquery/2.1.4/jquery.js"></script>

This video can help you solving your question :)
By: admin