When using Maven, if we want to rely on a local jar package, we usually use <scope>system</scope> and <systemPath>{yourlibpath}</systemPath> to handle it. By using the Class-Path header in the manifest, you can avoid having to specify a long -classpath flag when invoking Java to run your application.
But if you just do the above, when you use the SpringBoot packaging plugin to generate a jar package, you will find that the jar package will not be typed in, and an error will occur. The error usually is a runtime error like "NoClassDefFoundError". <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <includeSystemScope>true</includeSystemScope> </configuration> </plugin> Optional Solution: use maven-jar-plugin manifestEntriesif your jar file will not executed by Spring Boot, you want run it via java command. You can list system lib jar files in <manifestEntries /> section via maven-jar-plugin. <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <mainClass>com.SprintBootApplication</mainClass> </manifest> <manifestEntries> <Class-Path>your external jar files</Class-Path> </manifestEntries> </archive> </configuration> </plugin> by doing the above, you will see a MANIFEST.MF is packaged inside your app's jar. A tip to check jar file in your IDEclick any jar file in your IDE, add it as Library dependency for your app. Then you can view what are packaged inside the jar. Then in the Project explorer, you can view the external dependencies. References |
No comments:
Post a Comment