DevL
DevL

Reputation: 33

How to use webjars with Maven without any framework

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:

<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>

Upvotes: 3

Views: 3320

Answers (1)

Volodymyr Masliy
Volodymyr Masliy

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

Related Questions