2017-05-30 5 views
2

私が取り組んでいる特定のシナリオの答えは見つかりませんでした。私はMaven Web Projectを持っています。これはTomcat Server上で実行したいところです(これまでのところうまく動作しています)。私の問題は、jQueryとBootstrapを使う必要があることですが、それはうまくいかず、正式なリソースは追加のフレームワークなしで使うことができません。フレームワークなしでMavenでwebjarsを使用する方法

私がこれまでにやっていることです:

  • 私のpom.xmlはこのようになりますし、必要なすべての依存関係があります。

    <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> 
    
  • ターゲット/ appNameの/ WEB-INFを/ libフォルダには、jQuery、Bootstrap、その他の依存ライブラリのjarファイルが含まれています

  • これをindex.htmlやindex.jspで使用したい場合、リソースが見つかりません。 index.htmlには、(チュートリアルの例)次のようになります。

<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は私target/appName/フォルダ内にあると私は参照されている"target/appName/webjars/jquery/3.1.1/jquery.min.js"下に参照されたファイルを知っていますindex.htmlからは存在しませんが、私は何を知る必要がありますか?私はMavenがそれをすると思った。

答えて

1

まず、あなたはwebjars-locator依存関係を修正しました。


今、あなたの質問に: "/" の前除去することによって、あなたのJSとCSSのインポートを修正: 変更<script src="/webjars/.../>

<script src="webjars/.../>にチェックfull exampleを、あなたはこれが動作します

希望をしたい場合。

関連する問題