springboot默认打包的jar根目录下不是classes的内容,而是将classes和lib放在了BOOT-INF目录下,这样的jar只能独立运行,不能作为其他项目的依赖安装到maven仓库(无论本地或远程)
如果要作为依赖引用,正确的做法是手动打包普通格式的jar,再进行install,参考脚本如下:
springboot-install.bat
:
@echo off
rem springboot install
setlocal EnableDelayedExpansion
set O=springboot-demo
echo ----- packaging START -----
call mvn -f %O%\pom.xml clean compile jar:jar source:jar javadoc:javadoc javadoc:jar -Dmaven.test.skip=true
echo ----- packaging END -----
echo ----- install START -----
for /r "%O%\target" %%f in (*.jar) do (
echo processing `%%f` ...
set CLASSIFIER=
echo %%f| Findstr /r /c:"-sources\.jar$" > nul && set CLASSIFIER=sources
echo %%f| Findstr /r /c:"-javadoc\.jar$" > nul && set CLASSIFIER=javadoc
call mvn -f %O%\pom.xml install:install-file ^
-Dfile=%%f ^
-DpomFile=pom.xml ^
-Dclassifier=!CLASSIFIER! ^
-Dmaven.test.skip=true
)
echo ----- install END -----
其中springboot-demo
为需要打包的springboot项目所在的路径
注意:echo %%f|
这里管道符之前不能有空格,否则后面findstr处理时也会多一个空格,造成匹配失败