maven依賴本地非repository中的jar包-依賴jar包放在WEB-INF/lib等目錄下的情況用戶端編譯出錯的處理

來源:互聯網
上載者:User

標籤:style   blog   http   color   使用   os   io   ar   

maven依賴本地非repository中的jar包 

http://www.cnblogs.com/piaolingxue/archive/2011/10/12/2208871.html

部落格分類: 
MAVEN 
今天在使用maven編譯打包一個web應用的時候,碰到一個問題: 
項目在開發是引入了依賴jar包,放在了WEB-INF/lib目錄下,並通過buildpath中將web libariary匯入。 
在eclipse中開發沒有問題,但是使用maven編譯外掛程式開始便宜總是報找不到WEB-INF/lib這個jar包中的類。 
顯然實在編譯的時候WEB-INF/lib並沒有配置到maven-complier-plugin外掛程式src目錄中去, 
於是將這個目錄添加進去,還是不好使。無賴,先把這個jar包安裝到本地庫中,然後添加dependency。 

後來google了下,發現maven提供了scope為system的依賴,文檔的原文如下: 
system 
This scope is similar to provided except that you have to provide the JAR which contains it explicitly. 
The artifact is always available and is not looked up in a repository. 

這樣就可以添加dependency而不需要再將WEB-INF/lib目錄下的jar包安裝到本地庫中了。 
具體配置錄下: 
Xml代碼 
<dependency> 
<groupId>org.apache</groupId> 
<artifactId>test</artifactId> 
<version>1.0</version> 
<scope>system</scope> 
<systemPath>${basedir}/src/main/webapp/WEB-INF/lib/paypal_base.jar</systemPath> 
</dependency> 

!更好的方式是配置編譯參數<compilerArguments>,添加extdirs將jar包相對路徑添加到配置中,如下:

<build>
        <plugins>
            <plugin>
              <artifactId>maven-compiler-plugin</artifactId>
              <configuration>
                  <source>1.6</source>
                  <target>1.6</target>
                  <encoding>UTF-8</encoding>
                  <compilerArguments>
                   <extdirs>src\main\webapp\WEB-INF\lib</extdirs>
                 </compilerArguments>
              </configuration>
            </plugin>
        </plugins>
    </build>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.