PropertiesLauncher with Spring Boot 2 (and running a WAR archive)

强颜欢笑 提交于 2020-12-04 03:39:52

问题


I am creating a tomcat/jsp based WAR spring boot 2.0.4 executable which works pretty well when just using bootWar gradle target. But now I want to load local external JARs and WarLauncher doesnt support this (is there a reason for that?). So I switched to PropertiesLauncher via:

bootWar {
    enabled = true
    manifest {
        attributes 'Main-Class': 'org.springframework.boot.loader.PropertiesLauncher'
    }
}

Now looking inside the generated war file, everything looks ok in the MANIFEST like:

Start-Class: com.mypackage.Application
Main-Class: org.springframework.boot.loader.PropertiesLauncher

Now I tried to figure out the right command line args to start this thing which was a bit of trial and error but that got me nearly to the finish line:

java -Dloader.path=WEB-INF/lib-provided,WEB-INF/lib,WEB-INF/classes -jar myapplication-4.0.0.war

So I basically looked at WarLauncher and tried to recreate the classpath via loader.path values without adding 3rd party jars because first I just want to start my application.

The loading of my application looks ok.

Now I want to add a "local" path where my 3rd party jars reside. I thought I can just do:

java -Dloader.path=WEB-INF/lib-provided,WEB-INF/lib,WEB-INF/classes,jar:file:lib -jar myapplication-4.0.0.war

so adding a jar:file:lib which should mean the "lib" folder next to my runnable WAR. But this doesnt work. Also just adding ",lib" to the loader.path doesnt work.

The only thing that works is adding the full path like "jar:file:/foo/bar/lib" but i really would like to have it relative to current runnable WAR folder.

Can someone tell me how to define the relative local folder where to scan for Jars?

I hope i will help others struggling with PropertiesLauncher in combination with runnable WAR files because its not really straighforward and there is not much documentation apart from https://docs.spring.io/spring-boot/docs/current/reference/html/executable-jar.html


回答1:


Answering my own question but it might be helpful because the official docs are not that good.

If you want to include a defined JAR file you can use:

-Dloader.path=file:/myfolder/my.jar

If you want to include a whole director with multiple jars, you can do:

-Dloader.path=file:/myfolder/

(you can simply make the folder relativ to the WAR by using file:myfolder)

The other variants like reading from inside JAR could be get by reading the code at https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/PropertiesLauncher.java

What really helped was the debug flag:

-Dloader.path=file:/myfolder/ -Dloader.debug=true

You will get system.outs regarding the classloading issues with the PropertiesLauncher.

I really would like to see a -Dloader.schema=war flag which assume the WAR layout instead of the JAR layout. This way one would only need to add his own paths and not the needed folders inside the WAR.



来源:https://stackoverflow.com/questions/52218808/propertieslauncher-with-spring-boot-2-and-running-a-war-archive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!