Intellij spring boot PropertiesLauncher

Gui*_*oll 3 java intellij-idea maven spring-boot

我有 spring boot 应用程序(1.3.5.RELEASE),它打包为 jar 文件,我希望将 jdbc 驱动程序放在外部 libs 文件夹中。所以我使用 PropertiesLauncher 来搜索外部 jar 文件。

使用时工作正常java -jar -Dloader.path=lib/,但在 Intellij IDE 中不起作用。它是一个导入到 Intellij 中的 Maven 项目。

有什么提示给我吗?

Tam*_*ama 6

根据安迪的回答,我想我会发布我是如何解决它的:

  1. 我已经添加了依赖项的配置文件

    <profile>
        <id>intellij-properties-launcher</id>
    
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-loader</artifactId>
                <version>2.0.6.RELEASE</version>
            </dependency>
        </dependencies>
    
    </profile>
    
    Run Code Online (Sandbox Code Playgroud)
  2. 我在 Maven 选项卡上激活了 Intellij 上的配置文件

    在 IDE 上激活

  3. 根据andy改变了配置 运行配置

注意:Intellij Ultimate 2018.3。它会将配置标记为无效,但它可以工作:)

我希望能帮助某人。

  • 感谢您的精彩回答,对我帮助很大。 (2认同)

And*_*son 5

当您使用PropertiesLauncher它时,它会使用配置的内容设置一个类加载器loader.path,然后使用该类加载器加载并调用应用程序的主类。当您直接在 IDE 中启动应用程序的主类时,PropertiesLauncher不会涉及,因此loader.path系统属性不起作用。

它可以PropertiesLauncher在您的 IDE 中使用,但需要一些额外的配置。您需要配置一个运行配置,该配置spring-boot-loader在启动的类路径上包含您的应用程序PropertiesLauncher。然后,您可以使用loader.main系统属性来告知PropertiesLauncher应用程序主类的名称。