本文介绍了使用Spring Boot 2的PropertiesLauncher(并运行WAR归档文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个基于tomcat / jsp的WAR spring boot 2.0.4可执行文件,当仅使用bootWar gradle目标时,效果很好。但是现在我想加载本地外部JAR,而WarLauncher不支持此操作(是否有原因?)。因此,我通过以下方式切换到PropertiesLauncher:

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提供的,WEB-INF / lib,WEB-INF / classes -jar myapplication-4.0.0.war

所以我基本上看了WarLauncher并试图通过loader.path值重新创建类路径,而没有添加第3方jars,因为首先我只想启动我的应用程序。

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提供,WEB-INF / lib,WEB-INF / classes ,jar:file:lib -jar myapplication-4.0.0.war

添加一个 jar:file:lib 应该表示我的可运行WAR旁边的 lib文件夹。但这不起作用。只是将,lib添加到loader.path也不起作用。

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.

唯一可行的方法是添加完整路径,例如 jar:file:/ foo / bar / lib,但我真的很想让它相对于当前可运行的WAR文件夹。

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.

有人可以告诉我如何定义相对本地文件夹来扫描Jars吗?

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

我希望我能帮助其他在PropertiesLauncher上苦苦挣扎并与可运行的WAR文件结合使用的人,因为它的确不是简单易懂,并且除了

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

推荐答案

回答我自己的问题,但这可能会很有帮助,因为官方文档不是很好。

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

如果要包含已定义的JAR文件,可以使用:

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

如果需要要包括具有多个罐子的整个导演,您可以执行以下操作:

-Dloader.path=file:/myfolder/

(您可以使用file:myfolder使文件夹相对于WAR相对简单)

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

通过从

真正有用的是调试标志:

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

您将获得有关PropertiesLauncher类加载问题的system.outs。

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

我真的很想看到 -Dloader.schema = war 标志,该标志采用WAR布局而不是JAR布局。这样,一个人只需要添加自己的路径,而无需在WAR中添加所需的文件夹。

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.

这篇关于使用Spring Boot 2的PropertiesLauncher(并运行WAR归档文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 00:05