WebJars 進行 css js 資源文件管理


WebJars是將這些通用的Web前端資源打包成Java的Jar包,然后借助Maven工具對其管理,保證這些Web資源版本唯一性,升級也比較容易。關於webjars資源,有一個專門的網站http://www.webjars.org/,我們可以到這個網站上找到自己需要的資源,在自己的工程中添加入maven依賴,即可直接使用這些資源了

1. 使用

      添加依賴

      

<dependency>
            <groupId>org.webjars</groupId>
            <artifactId>webjars-locator</artifactId>
            <version>0.1</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>bootstrap</artifactId>
            <version>2.1.1</version>
        </dependency>

  

2. 打包:

      

 <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>

  

3. 引用

   a.靜態頁面:

 

   

 <link rel='stylesheet' href='webjars/bootstrap/2.1.1/css/bootstrap.min.css'>
    <script type='text/javascript' src='webjars/jquery/1.8.2/jquery.min.js'></script>
    <script type='text/javascript' src='webjars/bootstrap/2.1.1/js/bootstrap.min.js'></script>
    
     <script type='text/javascript' src='webjars/ajax-form/2.1.3/ajax-form.js'></script>
  

 b.jsp 

 

  

<link rel='stylesheet' href='<%= org.webjars.AssetLocator.getWebJarPath("css/bootstrap.min.css") %>'>
    <script type='text/javascript' src='<%= org.webjars.AssetLocator.getWebJarPath("jquery.min.js") %>'></script>
    <script type='text/javascript' src='<%= org.webjars.AssetLocator.getWebJarPath("js/bootstrap.min.js") %>'></script>
    
    
    
    
      <script type='text/javascript' src='<%= org.webjars.AssetLocator.getWebJarPath("ajax-form.js") %>'></script>
    

  

  

 

 

   


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM