๐ซฃ Well, I'm not sure, but maybe I can be called a full stack developer, just not so good.
๐ https://yaohwu.xyz
๐ https://wakatime.com/@yaohwu
๐ notes
Home Page: http://notes.yaohwu.xyz/
๐ซฃ Well, I'm not sure, but maybe I can be called a full stack developer, just not so good.
๐ https://yaohwu.xyz
๐ https://wakatime.com/@yaohwu
This is the docs for my project spring boot version
https://docs.spring.io/spring-boot/docs/2.1.3.RELEASE/
This is the issue about this problem
spring-projects/spring-boot#4375
I want using maven shade plugin jar first cause the final jar will be smaller I think.
Even though I cannot using java -jar , java -cp "lib.jar" Main is ok for me.
I tried this pom.xml config.
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<excludes>
<exclude>com.fr.third:fine-third</exclude>
</excludes>
</artifactSet>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>cloud-swift-fatty</shadedClassifierName>
</configuration>
</execution>
</executions>
</plugin>
But the final jar can not work when I using java -cp "lib.jar" Main.
Here is the exception.
java.lang.IllegalArgumentException: No auto configuration classes found in META-INF/spring.factories. If you are using a custom packaging, make sure that file is correct.
at org.springframework.util.Assert.notEmpty(Assert.java:464) ~[swift-spring-boot-2021.11-FEATURE-SNAPSHOT-cloud-swift-fatty.jar:na]
at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.getCandidateConfigurations(AutoConfigurationImportSelector.java:183) ~[swift-spring-boot-2021.11-FEATURE-SNAPSHOT-cloud-swift-fatty.jar:na]
......
I tried spring boot mvn plugin using this pom.xml config.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.3.RELEASE</version>
<configuration>
<fork>true</fork>
<mainClass>${start-class}</mainClass>
<excludes>
<exclude>
<groupId>com.fr.third</groupId>
<artifactId>fine-third</artifactId>
</exclude>
</excludes>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
While here is the final jar format.
example.jar
|
+-META-INF
| +-MANIFEST.MF
+-org
| +-springframework
| +-boot
| +-loader
| +-<spring boot loader classes>
+-BOOT-INF
+-classes
| +-mycompany
| +-project
| +-YourClasses.class
+-lib
+-dependency1.jar
+-dependency2.jar
You can find docs here
https://docs.spring.io/spring-boot/docs/current/reference/html/executable-jar.html
And the current module will be compiled into BOOT-INF/classes, but the other modules into BOOT-INF/lib.
Thing change worse.
spring-projects/spring-boot#4375
I found some module class cannot be loaded by Classloader.loadClass().
As so far, what should I do is using both of them, maven shade plugin and spring boot maven plugin.
Here is the config of pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.3.RELEASE</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<excludes>
<exclude>com.fr.third:fine-third</exclude>
</excludes>
</artifactSet>
<!--https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/2.1.3.RELEASE/spring-boot-starter-parent-2.1.3.RELEASE.pom-->
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer
implementation="org.springframework.boot.maven.PropertiesMergingResourceTransformer">
<resource>META-INF/spring.factories</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>${start-class}</mainClass>
</transformer>
</transformers>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>cloud-swift-fatty</shadedClassifierName>
</configuration>
</execution>
</executions>
</plugin>
But I find some controllers cannot be scanned by spring cause the SpringBootApplication
@ComponentScan(
excludeFilters = {@Filter(
type = FilterType.CUSTOM,
classes = {TypeExcludeFilter.class}
), @Filter(
type = FilterType.CUSTOM,
classes = {AutoConfigurationExcludeFilter.class}
)}
)
public @interface SpringBootApplication {
// ......
}
maven shade plugin may not create correct auto configuration for spring boot.
I have to change the code.
Update:
Controller not found is caused by my spring boot module not shade other module jars which contain other controller.
No need to change code.
I change spring boot maven plugin config to app module from spring boot module, and then it works.
@SpringBootApplication(scanBasePackages = "com.fr.swift.cloud")
Finally, all is ok.
At least for now.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.