Reputation: 33
I did not find an answer for the specific scenario I am working on. I have a Maven Web Project, which I want to run on a Tomcat Server (which is working fine so far). My problem is, that I need to use jQuery and Bootstrap, but it does not work and the official resources do not provide a way to use it without any additional framework.
That is what I have done so far:
My pom.xml looks like this and has all the necessary dependencies:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.ls5.wt2</groupId>
<artifactId>micro</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>micro Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>webjars-locator</artifactId>
<version>0.1</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>webjars-locator</artifactId>
<version>0.32-1</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.7</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
</dependency>
</dependencies>
<build>
<finalName>micro</finalName>
</build>
</project>
The target/appName/WEB-INF/lib folder contains the jar files for jQuery, Bootstrap and all of the other dependent libs
<html>
<head>
<script src="/webjars/jquery/3.1.1/jquery.min.js"></script>
<script src="/webjars/bootstrap/3.3.7-1/js/bootstrap.min.js"></script>
<title>WebJars Demo</title>
<link rel="stylesheet"
href="/webjars/bootstrap/3.3.7-1/css/bootstrap.min.css" />
</head>
<body>
<div class="container"><br/>
<div class="alert alert-success">
<a href="#" class="close" data-dismiss="alert"
aria-label="close">×</a>
<strong>Success!</strong> It is working as we expected.
</div>
</div>
</body>
</html>
index.html
is inside my target/appName/
folder and I know the referenced file under"target/appName/webjars/jquery/3.1.1/jquery.min.js"
which is referenced from the index.html
does not exist, but what do I need to do know? I thought maven would do that.Upvotes: 3
Views: 3320
Reputation: 413
First of all, you have duplicated webjars-locator dependency - fix that.
Now, on your question:
Fix your js and css imports by removing preceding "/":
Change <script src="/webjars/.../>
to <script src="webjars/.../>
Check full example, if you want
Hope this will work.
Upvotes: 1