background

Three plugins commonly used by Maven have different roles for packaging:

  1. Maven-jar-plugin: Handles jar package generation
  2. Spring-boot-maven-plugin: SpringBoot project packaging
  3. Maven-assembly-plugin: Custom packaging structure.

In the actual development process, these three plug-ins may be used together. This class introduces the matters needing attention when using these plug-ins together.

SpringBoot excludes files when packaging

When a SpringBoot project is packaged, it typically extracts configuration files and static resource files to a specified directory, and then specifies additional configuration files with –spring.config.additional-location=file: XXX.

Maven-ja-pluginr removes configuration files and static resource files from SpringBoot packaging:

< plugin > < groupId > org. Apache. Maven. Plugins < / groupId > < artifactId > maven - jar - plugin < / artifactId > < version > 3.2.0 < / version > <configuration> <excludes> <exclude>*.yml</exclude> <exclude>static/**</exclude> <exclude>lib/**</exclude> </excludes> </configuration> </plugin>Copy the code

Note: If you exclude folders, you need the following two stars.

Spring packages locally dependent jars

If your project needs to rely on a jar package in a local directory and it is not published in the repository, you can add the dependency as follows:

<dependency>
   <groupId>XXXX</groupId>
   <artifactId>XXX</artifactId>
   <version>1.0.0</version>
   <scope>system</scope>
  <systemPath>${project.basedir}/src/main/resources/lib/xxx.jar</systemPath>
</dependency>
Copy the code

It should be noted that if the project uses SpringBoot package plug-ins, system-scoped JARS will not be put into the lib directory by default, and include a suite of third-party JAR packages to add to the lib directory:

<plugin>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-maven-plugin</artifactId>
     <configuration>
         <includeSystemScope>true</includeSystemScope>
     </configuration>
 </plugin>
Copy the code

Exclude specified files at compile time

The resources configuration of POM.xml allows filtering of resource files. Common configurations are as follows:

<resources>
    <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
        <excludes>
            <exclude>static/**</exclude>
            <exclude>*.yml</exclude>
        </excludes>
    </resource>
</resources>
Copy the code

The classes directory in the target directory does not contain the specified files. As a result, the local runtime does not have configuration files. Therefore, it is not recommended to use this method during development.

Copy and paste principles

Think of a classic words I saw before:

One of the best lessons I’ve learned from the Internet is never to copy and paste code you didn’t write yourself. If you must copy, type it word for word and force yourself to think about what the code actually means.

In addition to the code needs to copy and paste, the usual documentation is also unavoidable to use the old document as a template.

In the process of writing a Word document, if the content is copied and pasted, my experience is that there are several checks to be made after completion:

  1. Title: Check whether the title and system name in the document are corrected to the content of the target document.
  2. Table of contents correction: when the page number of a document changes, you must regenerate the table of contents to match it.
  3. Proofread the revised content: proofread the revised content at least three times.

The revelation of

Today, I found a video introducing Zhou Zhiming on Info. I know he bought a book called “In-depth Understanding of Java Virtual Machine” when he first started his career. For such an IT Titan, IT is surprising that he has always kept the habit of writing code and submitted IT 1000 times a year on GitHub.

He says he works part-time as a programmer in management, and the decision not to write code is like many people who throw away basic knowledge of math and physics after graduation. Once thrown away, it’s hard to pick it up again.

Admiration arises spontaneously!