Maven jar外的SpringBoot依赖关系

时间:2020-09-12 01:54:57

标签: java spring-boot maven

我的SpringBoot项目有一个外部jar,该jar需要获取一些configFile,配置文件位于src/main/resources/config中,在mvn package之后,config位于BOOT-INF\classes\config中,但是外部jar得到的配置路径是:/BOOT-INF/lib/config-xxx-1.0.8.jar!/config,jar如何获得正确的路径?当我进行构思调试时,它可以获得正确的路径。 jar的代码:

 public static String getConfigPathUtil() {
        String configPath = ConfigPathUtil.class.getProtectionDomain().getCodeSource().getLocation().getPath();
        try {
            configPath = URLDecoder.decode(configPath, "utf-8");
        } catch (UnsupportedEncodingException var2) {
            throw new RuntimeException("Transcoding mistakes when the configuration file path" + var2.getMessage());
        }
        File f = new File(configPath);
        configPath = f.getAbsolutePath();
        if (configPath.endsWith(".jar")) {
            configPath = configPath.substring(0, configPath.lastIndexOf(LIB_PATH));
        }
        if (configPath.endsWith(BIN_PATH_ENDSWITH)) {
            configPath = configPath.substring(0, configPath.lastIndexOf(BIN_PATH_ENDSWITH));
        }
        configPath = configPath.replace(BIN_PATH, File.separator);
        configPath = configPath + CONFIG_PATH;
        return configPath;
    }

maven pom:

 <dependency>
            <groupId>xxx</groupId>
            <artifactId>config-xxx</artifactId>
            <version>1.0.8</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/src/main/resources/lib/config-xxx-1.0.8.jar</systemPath>
        </dependency>

springboo-maven-plugin

 <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                  <mainClass>com.xxx.ManagementApplication</mainClass>
               <includeSystemScope>true</includeSystemScope>
                </configuration>
            </plugin>

0 个答案:

没有答案