How do I install JQuery into my web app using Maven?
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
Comments
-
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 over 12 yearsHow do I add the war to my project using maven? Can I make transitive JavaScript dependencies?
-
Udo Held over 12 yearsYou 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 over 12 yearsOverlay documentation maven.apache.org/plugins/maven-war-plugin/examples/…
-
Udo Held over 12 yearsThat link indeed explains the behavior I was refering to. I've looked at it some time ago. :)
-
ams over 12 yearshosting from a CDN is not appropriate for this application, the application must be self contained with everything that it needs inside of it
-
Ph0b0x over 6 yearsHello, how do you use it in your JSP after you have added the dependency?