有两种方式:
1、单独打源码包,单独看jar包不能看源码。
mvn clean source:jar install
2、将源码打入到jar里
在pom中引用插件
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>2.3</version> <executions> <execution> <id>copy-resources</id> <phase>process-resources</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <outputDirectory>${project.build.outputDirectory}</outputDirectory> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.java</include> </includes> </resource> </resources> </configuration> </execution> </executions> </plugin>
参考:https://stackoverflow.com/questions/23933911/include-source-code-while-exporting-a-jar-using-maven
https://blog.csdn.net/wang465745776/article/details/52212871