Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the problems that should be paid attention to when maven packages resource files?

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

Today, I will talk to you about the problems that need to be paid attention to in maven packaging resource files, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.

Original intention

My purpose of writing this blog is to let you know the structure of some maven projects and what they look like after packaging, so that you can troubleshoot problems in the actual project. For example: I clearly wrote the xml of mybatis under src/main/java, why can't I read the project report wrong? I have configured configuration files for multiple environments, and I only choose one when I run it, so I don't want to package all the files under src/main/resources into target/classes. What should I do?

Standard directory structure of maven

When building a Maven project, without special configuration, Maven will find and process various types of files according to the standard directory structure. The standard directory structure is as follows:

Related configuration of maven resources

Src/main/java and src/test/java

All .java files in these two directories are compiled during the comile and test-comiple phases, respectively, and the compilation results are placed in the target/classes and targe/test-classes directories, respectively, but other files in these two directories (such as:. Xml, etc.) are ignored.

Src/main/resouces and src/test/resources

The files in these two directories are also copied to the target/classes and target/test-classes directories, respectively.

Target/classes

By default, the maven packaging plug-in will put everything in this directory into the jar package or war package.

Resource

Problems that maven resource needs to pay attention to. By default, maven will copy all the corresponding files to target according to the standard path. If you need to package some files selectively, you need to use resource.

Let's take the maven project mavenDemo that I created as an example.

Add the following configuration to the pom.xml of the mavenDemo project in order to package only the files with the suffixes properties and xml under src/main/resources into the classes file. The effect is shown in figure 1.

Use the clean package command of maven to package our project to the target file. Be sure to execute the clean command of maven before the package command. Using the package command directly may have a cache that prevents us from seeing the latest changes.

. Src/main/resources * * / * .yml * * / * .xml true.

We can see that after the project is packaged, the .sql file under src/main/resources is filtered out, leaving only the .yml and .xml configuration files.

After reading the above, do you have any further understanding of the problems that maven packaging resource files need to pay attention to? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report