简体   繁体   English

Spring 引导战争打包:使用附加类路径执行

[英]Spring Boot war packaging: Execution with additional classpath

I would like to package my Spring Boot application as a war package in order to我想将 package 我的 Spring 启动应用程序作为一战 package 以

  • deploy on existing tomcat部署在现有的 tomcat
  • running standalone with java -jar application.war使用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 .为了实现这一点,我将spring-boot-starter-tomcat的 scope 设置为provided ,因此这些依赖项位于文件夹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.在现有 tomcat 上运行时,我只需将数据库驱动程序(作为 jar)添加到其 lib 文件夹中。

Now my question: How can I add the additional classpath (eg lib/* ) to the java -jar application.war command?现在我的问题是:如何将额外的类路径(例如lib/* )添加到java -jar application.war命令? Traditional approaches (like java -cp lib/* -jar application.war ) did not work.传统方法(如java -cp lib/* -jar application.war )不起作用。

Found out that Spring Boot uses a WarLauncher to run executable war files.发现 Spring Boot 使用 WarLauncher 来运行可执行的战争文件。 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.是一个工作命令行命令,用于将额外的 jar 文件添加到类路径,而无需修改或解压缩 war 文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM