英文:
Spring Boot war packaging: Execution with additional classpath
问题
我想将我的Spring Boot应用程序打包为WAR包,以便
- 部署在现有的Tomcat上
- 使用
java -jar application.war
独立运行
使用相同的构件。为了实现这一点,我将 spring-boot-starter-tomcat
的范围设置为 provided
,以便这些依赖项位于 lib-provided
文件夹中。
我不想将数据库驱动程序包含在构件中。在现有的Tomcat上运行时,我只需将数据库驱动程序(作为JAR文件)添加到其lib文件夹中。
现在我的问题是:如何将额外的类路径(例如 lib/*
)添加到 java -jar application.war
命令中?传统的方法(如 java -cp lib/* -jar application.war
)不起作用。
英文:
I would like to package my Spring Boot application as a war package in order to
- deploy on existing tomcat
- running standalone with
java -jar application.war
with the same artifact. To achieve this I set the scope of spring-boot-starter-tomcat
to provided
so these dependencies are located in folder lib-provided
.
I don't want to include the Database driver in the artifact. When running on existing tomcat I just add the database driver (as jar) to its lib folder.
Now my question: How can I add the additional classpath (e.g. lib/*
) to the java -jar application.war
command? Traditional approaches (like java -cp lib/* -jar application.war
) did not work.
答案1
得分: 2
Spring Boot 使用 WarLauncher 来运行可执行的 WAR 文件。因此,
java -cp drivers/*:application.war org.springframework.boot.loader.WarLauncher
是一个可行的命令行命令,可以将额外的 JAR 文件添加到类路径,而无需修改或解压 WAR 文件。
英文:
Found out that Spring Boot uses a WarLauncher to run executable war files. So
java -cp drivers/*:application.war org.springframework.boot.loader.WarLauncher
is a working commandline command to add additional jar files to the classpath without modifying or unpacking the war file.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论