https://blog.csdn.net/abcwanglinyong/artic
項目中除了pom.xml依賴之外,有時還依賴了其他jar包,如圖:
依賴的方式如下:
點擊Project Structure進行項目設置,在Modules中Dependencies標簽中點擊+號 添加lib下的所有jar,如圖:
然后在Artifacts的Output Layout標簽中將依賴放到/WEB-INF/lib目錄下,如圖:
這樣的話項目中就可以使用lib中依賴的jar了,但是如果要打包則會報錯,須進行相關配置。
打war包的時候有兩種方式:
第一種方式
在pom.xml中的build標簽內容添加resources標簽,如下:
<resources>
<resource>
<directory>lib</directory>
<targetPath>BOOT-INF/lib/</targetPath>
<includes>
<include>**/*.jar</include>
</includes>
</resource>
</resources>
然后在plugin標簽的configuration標簽內加入compilerArguments標簽,如下:
<compilerArguments>
<!-- 打包本地jar包 -->
<extdirs>${project.basedir}/lib</extdirs>
</compilerArguments>
整體配置截圖如下:
然后使用maven命令進行打包即可:
install -Dmaven.test.skip=true
第二種方式
在pom.xml中通過以下方式引入lib中的每個依賴
<dependency>
<groupId>com.xxx.www</groupId>
<artifactId>out-jar-1</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/commons-cxxxx.jar</systemPath>
</dependency>
<dependency>
<groupId>com.xxx.www</groupId>
<artifactId>out-jar-2</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/commons-httxxxx.jar</systemPath>
</dependency>
....
其中groupId和artifactId可以隨便填,注意artifactId不要重復了
然后使用maven命令進行打包即可:
install -Dmaven.test.skip=true
如果是SpringBoot項目還要加如下配置:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
主要是
<includeSystemScope>true</includeSystemScope>
注意
1、如果啟動tomcat時一直卡在 Deploying web application archive ...
是因為linux或者windows系統提供隨機數設備是/dev/random 和/dev/urandom ,
urandom安全性沒有random高,但random需要時間間隔生成隨機數。jdk默認調用random。
解決步驟如下:
找到 jdk目錄/jre/lib/security/Java.security文件,在文件中找到securerandom.source這個設置項,將
securerandom.source=file:/dev/random
改為
securerandom.source=file:/dev/urandom
2、如果打包后項目找不到lib依賴,點擊Project Structure進行如下設置:
在Artifacts的Output Layout標簽中將依賴放到/WEB-INF/lib目錄下
保存配置即可!
————————————————
版權聲明:本文為CSDN博主「壞菠蘿」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/abcwanglinyong/article/details/90448497