Achieve goals
Maven packages, with the source code in the generated jar package. Remember, this source code means that the source code is placed in a jar file with the generated file instead of a separate Xxx-source.jar package.
Realize the idea
Treat the source code as a resource file
Implementation method One
<build> <resources> <resource> <directory>src/main/java</directory> </resource> </resources></build>
Description: The default resource folder is Src/main/resource, and this method modifies the resource folder so that your default resource folder becomes the Src/main/java folder. This folder is placed in Maven by default in the source code.
Cons: After modification, the Src/main/resource folder is not a resource folder, and the files placed in it will not be used as resources.
Implementation Method Two
<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</< Span class= "Hljs-title" >directory> <includes> <include>**/*.java</ include> </includes> </resource> </ resources> </configuration> Span class= "Hljs-tag" ></execution> </ executions></PLUGIN>
Description: Plug-in Maven-resources-plugin default processing resources and test resources, add resources to the folder ${project.build.outputDirectory} , this reference represents the output folder of the project. is typically the project's WEB-INF\classes folder. When you are packing, package the contents of this folder into a jar file. So if you want to package the source code inside the jar file, you need to add the source code to the folder as a resource file ${project.build.outputDirectory} .
Cons: Code is relatively long
Advantages: Do not modify the resource folder, the project structure does not change, it is recommended to use this kind of
Reference Resources
- http://stackoverflow.com/questions/25779900/how-to-include-source-file-java-file-parallel-to-class-file-in-the-generated
- Http://stackoverflow.com/questions/23933911/include-source-code-while-exporting-a-jar-using-maven
How Maven implements creating a jar package with source code