How to configure additional classpath in SpringBoot?

前端 未结 3 871
小鲜肉
小鲜肉 2020-12-17 09:14

I want to make a standalone web application. I have some problems with SpringBoot.

My application is one jar file from SpringBoot.

But my application was usu

相关标签:
3条回答
  • 2020-12-17 09:55

    In my case, it was needed " quote to find the external lib folder on windows platform

    java -cp ScoreExtractionApp.jar -Dloader.path="lib" -Dloader.main=com.sample.score.ScoreExtraction.ScoreExtractionApplication org.springframework.boot.loader.PropertiesLauncher
    
    0 讨论(0)
  • 2020-12-17 09:56

    You can use the loader.path parameter to define a location for an external lib folder. All jars under this folder will be added to the classpath. For example, if you'd like to define C:\extLib as your external lib folder, you can do the following:

    java -Dloader.path=/C:/extLib/ -jar aapName.jar
    

    For this to work, you need to use the PropertiesLauncher. There are two ways to do that:

    Option 1

    Update the project pom.xml and add the following tag:

    <configuration>  <!-- added -->
      <layout>ZIP</layout> <!-- to use PropertiesLauncher -->
    </configuration
    

    Effective build tag, the post-update looks like below:

    <build> 
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>  <!-- added -->
                    <layout>ZIP</layout> <!-- to use PropertiesLauncher -->
                </configuration>
            </plugin>
        </plugins>
    </build>
    

    Option 2

    Use the PropertiesLauncher when launching the application from the commandline:

    java -cp aapName.jar -Dloader.path=/C:/extLib/ org.springframework.boot.loader.PropertiesLauncher
    

    References:
    How to add jars to SpringBoot classpath with jarlauncher

    0 讨论(0)
  • 2020-12-17 10:10

    You may refer this below link from spring boot:

    https://docs.spring.io/spring-boot/docs/current/reference/html/executable-jar.html#executable-jar-property-launcher-features

    You can use the loader.path property to define a lib folder location

    0 讨论(0)
提交回复
热议问题