How do I install JQuery into my web app using Maven?

20,079

Solution 1

You could create your own "war" that has jquery in it on the path you specified.

Afterwards add that war to your real web application. Maven should merge it. I think it was called somehting like "processing overlay".

I'm using the same for some GWT application where the javascript is generated by a maven plugin and it works well.

Solution 2

Perhaps WebJars can help you:

WebJars are client-side web libraries (e.g. jQuery & Bootstrap) packaged into JAR (Java Archive) files.

  • Explicitly and easily manage the client-side dependencies in JVM-based web applications
  • Use JVM-based build tools (e.g. Maven, Gradle, & SBT) to download your client-side dependencies
  • Know which client-side dependencies you are using
  • Transitive dependencies magically appear

Caveat: WebJars does not put the jquery files in the webapp/js folder. Please read documentation to see how it is used with some popular frameworks.

Solution 3

Try adding this to your pom.xml file. It worked for me :

<dependency>
    <groupId>com.efsavage.jquery</groupId>
    <artifactId>jquery-maven</artifactId>
    <version>1.7.2</version>
</dependency>

This library gives you a way to drop jQuery into your project as a Maven dependency, which means you don't have to include these third party files in your own source control.

Source : here

Share:
20,079
ams
Author by

ams

I love software development.

Updated on March 27, 2020

Comments

  • ams
    ams about 4 years

    I am looking at using Maven 3 for some web development. I know how to use maven to resolve java based jar files. How do I use maven to resolve JavaScript dependencies for example I want to have maven automatically put jquery in my webapp/js folder?

    Is it possible to do transative JavaScript dependencies with Maven 3?

  • ams
    ams over 12 years
    How do I add the war to my project using maven? Can I make transitive JavaScript dependencies?
  • Udo Held
    Udo Held over 12 years
    You add it as a dependency of type war. Before you can add it to your other projects you need a web project with jquery in it and install it to your repository.
  • ams
    ams over 12 years
  • Udo Held
    Udo Held over 12 years
    That link indeed explains the behavior I was refering to. I've looked at it some time ago. :)
  • ams
    ams over 12 years
    hosting from a CDN is not appropriate for this application, the application must be self contained with everything that it needs inside of it
  • Ph0b0x
    Ph0b0x over 6 years
    Hello, how do you use it in your JSP after you have added the dependency?