1. 程式人生 > >WebJars——web端靜態資源打jar包

WebJars——web端靜態資源打jar包

WebJars是將web前端資源(js,css等)打成jar包檔案,然後藉助Maven工具,以jar包形式對web前端資源進行統一依賴管理,保證這些Web資源版本唯一性。WebJars的jar包部署在Maven中央倉庫上。

pom.xml:

<dependencies>
    <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>jquery</artifactId>
            <version>2.2.4</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>bootstrap</artifactId>
            <version>3.3.6</version>
        </dependency>
</dependencies>

靜態頁面:

<link rel='stylesheet' href='webjars/bootstrap/3.3.6/css/bootstrap.min.css'>

<script type='text/javascript' src='webjars/bootstrap/3.3.6/js/bootstrap.min.js'></script>

<script type='text/javascript' src='webjars/jquery/2.2.4/jquery.min.js'></script>

JSP頁面:

<link rel='stylesheet'  href="<%=request.getContextPath() %>/webjars/bootstrap/3.3.6/css/bootstrap.min.css"/>

<script type="text/javascript" src="<%=request.getContextPath() %>/webjars/bootstrap/3.3.6/js/bootstrap.min.js"></script>

<script type="text/javascript" src="<%=request.getContextPath() %>/webjars/jquery/2.2.4/jquery.min.js"></script>