美文网首页
将springboot项目打包成普通jar

将springboot项目打包成普通jar

作者: rainmanhhh | 来源:发表于2020-12-30 23:34 被阅读0次

    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处理时也会多一个空格,造成匹配失败

    相关文章

      网友评论

          本文标题:将springboot项目打包成普通jar

          本文链接:https://www.haomeiwen.com/subject/buwkoktx.html