一開始的時候,使用maven打包springboot,我都是將打好的包lib裏面的jar全部刪除。然後單獨複製一份lib文件,然後運行的時候使用
java -Djava.ext.dirs=D:\lib test
這樣很簡單,又很方便。但是後面項目集成shiro之後,就不行了。簡單的把lib裏面刪除,運行的時候就會報錯
java.security.NoSuchAlgorithmException: AES KeyGenerator not available
百度了很多都是什麼jdk的問題,其實我知道,這不是我要的答案,無意間發現一篇文章
https://blog.csdn.net/xrq0508/article/details/80050119
打開了新大門。我的pom.xml關鍵配置如下
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<!-- 指定 Spring Boot 啓動類,實際測試中必須 -->
<mainClass>com.hch.fifa.FifaApplication</mainClass>
<!-- 將所有第三方 jar 添加到項目 jar 的 MANIFEST.MF 文件中,這樣運行 jar 時依賴包才能被加載 -->
<addClasspath>true</addClasspath>
<!-- 指定複製第三方 jar 的目標目錄爲 target/lib/-->
<classpathPrefix>./lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!-- repackage 時排除掉 第三方依賴 jar 文件,我們的可運行 Spring Boot 的 jar 文件瞬間變小 ^_^ -->
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<includes>
<include>
<groupId>nothing</groupId>
<artifactId>nothing</artifactId>
</include>
</includes>
</configuration>
</plugin>
這樣運行的時候直接打命令
java test
就可以了
順便提一句,配置文件也可以放到jar包外面,參考如下
https://www.cnblogs.com/matd/p/11130906.html
關鍵說明如下
Spring程序會按優先級從下面這些路徑來加載application.properties配置文件
1、當前目錄下的/config目錄
2、當前目錄
3、classpath裏的/config目錄
4、classpath 跟目錄
因此,要外置配置文件就很簡單了,在jar所在目錄新建config文件夾,然後放入配置文件,或者直接放在配置文件在jar目錄
然後再放上我的application.yml
spring:
profiles:
active: dev
srping:
thymeleaf:
prefix: classpath:/templates/
mybatis:
typeAliasesPackage: com.hch.xconnect.entity
mapperLocations: classpath:/mapper/*.xml
---
#開發配置
spring:
profiles: dev
datasource:
url: jdbc:mysql://localhost:3306/fifa?useSSL=false
username: root
password: 123456
driver-class-name: com.mysql.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource
initialSize: 5
minIdle: 5
maxActive: 20
maxWait: 60000
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: SELECT 1 FROM DUAL
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
thymeleaf:
encoding: UTF-8
mode: HTML
servlet:
content-type: text/html
cache: false
servlet:
multipart:
max-file-size: 100MB
max-request-size: 5000MB
server:
port: 61193
properties:
uplaodFilePath: /usr/local/upload/
version: 1.0
staticResourcesPath: /Users/workspaces/fifa/src/main/resources/static/
---
#生產
spring:
profiles: pro
datasource:
url: jdbc:mysql://localhost:63306/fifa?useSSL=false
username: root
password: Zz.123.123
driver-class-name: com.mysql.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource
initialSize: 5
minIdle: 5
maxActive: 20
maxWait: 60000
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: SELECT 1 FROM DUAL
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
encoding: UTF-8
mode: HTML
servlet:
content-type: text/html
cache: true
servlet:
multipart:
max-file-size: 100MB
max-request-size: 5000MB
server:
port: 61193
properties:
uplaodFilePath: /usr/local/upload/
version: 1.0
staticResourcesPath: /usr/local/fifa/static/
配置那個active: dev或者pro就可以指定不同配置