明天的明天 永远的永远 未知的一切 我与你一起承担 ??

是非成败转头空 青山依旧在 几度夕阳红 。。。
  博客园  :: 首页  :: 管理

根目录pom.xml

 <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.5.12</version>
                <configuration>
                    <includeSystemScope>true</includeSystemScope>
                    <excludes>
                        <!-- classpath (-cp):JVM原生的类路径机制 cmd 启动如下(路径需包含 项目snowy-common/lib/的依赖包) >> java -Dfile.encoding=utf-8 -cp "snowy-web-app-2.0.0.jar;D:/web/libs/*"  -->
                        <!-- 排除ZOS相关jar包 -->
                        <exclude>
                            <groupId>com.amazonaws</groupId>
                            <artifactId>zos-java-sdk-s3</artifactId>
                        </exclude>
                        <exclude>
                            <groupId>com.amazonaws</groupId>
                            <artifactId>zos-java-sdk-sts</artifactId>
                        </exclude>
                        <exclude>
                            <groupId>com.amazonaws</groupId>
                            <artifactId>aws-java-sdk-iam</artifactId>
                        </exclude>
                        <exclude>
                            <groupId>org.bouncycastle</groupId>
                            <artifactId>bcprov-jdk18on</artifactId>
                        </exclude>
                        <exclude>
                            <groupId>org.bouncycastle</groupId>
                            <artifactId>bcprov-ext-jdk18on</artifactId>
                        </exclude>
                        <!-- 排除Aspose相关jar包 -->
                        <exclude>
                            <groupId>com.aspose</groupId>
                            <artifactId>aspose-cells</artifactId>
                        </exclude>
                        <exclude>
                            <groupId>com.aspose</groupId>
                            <artifactId>aspose-pdf</artifactId>
                        </exclude>
                        <exclude>
                            <groupId>com.aspose</groupId>
                            <artifactId>aspose-slides</artifactId>
                        </exclude>
                        <exclude>
                            <groupId>com.aspose</groupId>
                            <artifactId>aspose-words</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

 

启动 .bat (loader.path:Spring Boot的自定义类加载机制)

@echo off

title API-%date%-%time%-%cd%
java -Dfile.encoding=utf-8  -jar -Xms1024m -Xmx2048m -XX:PermSize=128M -XX:MaxPermSize=256M -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=6001 D:\web-project\api\snowy-web-app-2.0.0.jar --spring.datasource.dynamic.publickey=MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJPgN1/eGaJCQ2Nd7sDQUsEUFIgfS2kR+3ZK+a4qm4pobjc7zrnXLsBgYJCM+aIgXlfPjexj8b7U2Kxf3RO2qrECAwEAAQ==

或者

@echo off

title PMP_API-%date%-%time%-%cd%


java -Dfile.encoding=utf-8 -Dloader.path="D:/web/libs/*"  -Xms1024m -Xmx4096m -XX:PermSize=128M -XX:MaxPermSize=256M -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=6001 -jar snowy-web-app-2.0.0.jar --spring.datasource.dynamic.publickey=MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAIamTaG0e6ylJcLqdktHjQh4Jbm7RzCqn0+H8Y2Tu9oR6+Byw0KIu5r9nzIssJx/3exyFPoD9TuCuCmxDrz3XgUCAwEAAQ==

 


 

调用服务器目录依赖的  .bat  (classpath (-cp):JVM原生的类路径机制)

@echo off

title PMP_API-%date%-%time%-%cd%

java -Dfile.encoding=utf-8 -cp "snowy-web-app-2.0.0.jar;D:/web/libs/*" -Xms1024m -Xmx4096m -XX:MetaspaceSize=128M -XX:MaxMetaspaceSize=256M -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=6001 org.springframework.boot.loader.JarLauncher --spring.datasource.dynamic.publickey=MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAIamTaG0e6ylJcLqdktHjQh4Jbm7RzCqn0+H8Y2Tu9oR6+Byw0KIu5r9nzIssJx/3exyFPoD9TuCuCmxDrz3XgUCAwEAAQ==

 

 

loader.path vs classpath 的区别

  1. loader.path:Spring Boot的自定义类加载机制,有时对某些复杂依赖(如Aspose)的加载顺序和方式有限制

  2. classpath (-cp):JVM原生的类路径机制,直接告诉JVM去哪里找类文件,加载更直接可靠

具体差异

  •  

    loader.path
     通过Spring Boot的LaunchedURLClassLoader加载外部jar

     

  •  

    classpath
     直接将jar包加入JVM的系统类路径,优先级更高

     

对于像Aspose这种商业库,往往有复杂的内部依赖关系,用JVM原生的classpath机制更稳定。

所以当

loader.path

找不到类时,

classpath

方式通常能解决问题。

 =====================================================

方案A:使用 -cp 参数(推荐)

java -cp "D:\libs\*" -jar snowy-web-app.jar
bash

方案B:使用 -Dloader.path 参数

java -Dloader.path="D:\libs" -jar snowy-web-app.jar
bash