【Maven】自定义Maven插件
场景:
1、自定义一个插件目标 timer,用于显示当前日期时间。
2、将 timer 绑定到 validate 阶段。
调研
1、maven-clean-plugin
下载 maven-clean-plugin 插件的源码,在本地使用 IDEA 打开
可以看到,maven-clean-plugin 插件是由单个 Maven 工程实现的,CleanMojo 是 clean 目标的实现类。
2、maven-compiler-plugin
下载 maven-compiler-plugin 插件的源码,在本地使用 IDEA 打开
可以看到,maven-compiler-plugin 插件是由单个 Maven 工程实现的,CompilerMojo 是 compile 目标的实现类,TestCompilerMojo 是 testCompile 目标的实现类。
3、maven-surefire-plugin
下载 maven-surefire-plugin 插件 2.14.2 版本的源码,在本地使用 IDEA 打开
可以看到,maven-surefire-plugin 插件整体是一个聚合工程,在聚合工程中有一个 module 用于实现 test 目标。
4、maven-jar-plugin
下载 maven-jar-plugin 插件的源码,在本地使用 IDEA 打开
可以看到,maven-jar-plugin 插件是由单个 Maven 工程实现的,JarMojo 是 clean 目标的实现类。
5、maven-install-plugin
下载 maven-install-plugin 插件的源码,在本地使用 IDEA 打开
可以看到,maven-install-plugin 插件是由单个 Maven 工程实现的,InstallMojo 是 install 目标的实现类。
6、maven-deploy-plugin
下载 maven-deploy-plugin 插件的源码,在本地使用 IDEA 打开
可以看到,maven-deploy-plugin 插件是由单个 Maven 工程实现的,DeployMojo 是 deploy 目标的实现类。
总结:
1、项目的结构
一般情况下,一个插件对应一个项目,在 src/main/java 目录下实现插件的目标,实现类的类名是"目标名Mojo"。maven-surefire-plugin 较为特殊,定义了一个聚合工程,其 test 目标是在自模块 maven-surefire-plugin 中实现的。总体来看,一个插件对应一个工程。如果插件较为复杂,可以考虑创建聚合工程,使用子模块实现插件目标。
2、pom 文件的项目描述符
groupId | 一般为公司域名倒序 |
---|---|
artifactId | 插件的名称 |
version | 插件的版本 |
packaging | 必须设置为 maven-plugin |
dependencies | 必须引入 maven-plugin-api 和 maven-plugin-annotations |
说明:
- maven-plugin-api:这个依赖提供了编写 Maven 插件所需的核心 API。它包括了
Mojo
接口和一些其他的基础类,这些是你在创建自己的 Maven 目标(goals)时所必需的。 - maven-plugin-annotations:此依赖包含用于注解 Maven 插件组件的注解,比如
@Mojo
和@Parameter
等。这些注解帮助描述插件的行为和配置,并且是在编译期由 Maven 插件工具处理的。
3、其他标签元素:
- 还可以指定其他信息,如插件名称 name、描述 description、开始开发的年份 inceptionYear、贡献者 contributor 等。
开发Maven插件的步骤
1、创建 Maven 工程
- 在工程的 pom 文件中设置标签,如 GAV、packaging、description等,其中前两者必须设置。
- 在 pom 文件中引入必要的依赖 maven-plugin-api 和 maven-plugin-annotations。
2、创建目标类Mojo
- 使用 @Mojo 注解,name 属性指定目标名称
- 重写 execute 方式,实现目标的功能逻辑
- 添加属性
3、打包插件工程,安装到本地仓库或部署到远程仓库(私服)
4、引用插件,运行插件
- 直接运行插件
- 或将目标绑定到特定生命周期阶段(可选)
- 无论选择哪种运行方式,都可以在命令行指定参数
环境设置
1、JDK:1.8.0_131
2、Maven:Apache Maven 3.8.8
3、IntelliJ IDEA:2024.1.1 (Ultimate Edition)
实现
1、创建工程
maven-clean-plugin 是 Maven 中相对简单的一个插件,我们可以仿照该插件的目录结构创建一个项目。
(1) 选择 Maven Archetype
- 在 Archetype 下拉框中选择 org.apache.maven.archetypes:maven-archetype-plugin
- 设置 ArtifactId
- Create
控制台打印:
C:\Softwares\Developer_Kits\JDK\jdk1.8.0_131\bin\java.exe -Dmaven.multiModuleProjectDirectory=C:\Users\ ......
[INFO] Scanning for projects...
Downloading from myphoenix-nexus: http://localhost:8081/repository/maven-public/org/apache/maven/plugins/maven-archetype-plugin/maven-metadata.xml
Downloaded from myphoenix-nexus: http://localhost:8081/repository/maven-public/org/apache/maven/plugins/maven-archetype-plugin/maven-metadata.xml (1.1 kB at 1.0 kB/s)
Downloading from myphoenix-nexus: http://localhost:8081/repository/maven-public/org/apache/maven/plugins/maven-archetype-plugin/3.3.1/maven-archetype-plugin-3.3.1.pom
Downloaded from myphoenix-nexus: http://localhost:8081/repository/maven-public/org/apache/maven/plugins/maven-archetype-plugin/3.3.1/maven-archetype-plugin-3.3.1.pom (10 kB at 21 kB/s)
Downloading from myphoenix-nexus: http://localhost:8081/repository/maven-public/org/apache/maven/archetype/maven-archetype/3.3.1/maven-archetype-3.3.1.pom
Downloaded from myphoenix-nexus: http://localhost:8081/repository/maven-public/org/apache/maven/archetype/maven-archetype/3.3.1/maven-archetype-3.3.1.pom (10 kB at 20 kB/s)
Downloading from myphoenix-nexus: http://localhost:8081/repository/maven-public/org/apache/groovy/groovy-bom/4.0.23/groovy-bom-4.0.23.pom
Downloaded from myphoenix-nexus: http://localhost:8081/repository/maven-public/org/apache/groovy/groovy-bom/4.0.23/groovy-bom-4.0.23.pom (27 kB at 48 kB/s)
Downloading from myphoenix-nexus: http://localhost:8081/repository/maven-public/org/apache/maven/plugins/maven-archetype-plugin/3.3.1/maven-archetype-plugin-3.3.1.jar
Downloaded from myphoenix-nexus: http://localhost:8081/repository/maven-public/org/apache/maven/plugins/maven-archetype-plugin/3.3.1/maven-archetype-plugin-3.3.1.jar (99 kB at 165 kB/s)
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:3.3.1:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:3.3.1:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO]
[INFO]
[INFO] --- maven-archetype-plugin:3.3.1:generate (default-cli) @ standalone-pom ---......[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: maven-archetype-plugin:1.2
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: cn.myphoenix
[INFO] Parameter: artifactId, Value: timer-maven-plugin
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: package, Value: cn.myphoenix
[INFO] Parameter: packageInPathFormat, Value: cn/myphoenix
[INFO] Parameter: package, Value: cn.myphoenix
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: groupId, Value: cn.myphoenix
[INFO] Parameter: artifactId, Value: timer-maven-plugin
[INFO] Project created from Archetype in dir: C:\Users\MyPhoenix\AppData\Local\Temp\archetypetmp\timer-maven-plugin
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 27.799 s
[INFO] Finished at: 2024-12-06T20:53:56+08:00
[INFO] ------------------------------------------------------------------------
(2) 修改pom文件
- GAV
- packaging 必须设置为 maven-plugin
- 必须引入 maven-plugin-api 和 maven-plugin-annotations,这样才能在编写 Mojo 目标类时继承 AbstractMojo 和使用注解。
- maven-plugin-plugin 可选,下面的方式是使用 aven-plugin-plugin:helpmojo 生成自定义插件的 help 目标。(官方推荐这样做)
- properties 标签内部定义编码方式、JDK 版本、源码和编译代码的版本等。
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>cn.myphoenix</groupId><artifactId>timer-maven-plugin</artifactId><version>1.0-SNAPSHOT</version><packaging>maven-plugin</packaging><name>timer-maven-plugin Maven Plugin</name><description>The Maven Timer Plugin is a plugin that displays the current time in the default timezone.</description><inceptionYear>2024</inceptionYear><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><!-- 配置Maven编译的时候采用的编译器版本 --><maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion><!-- 指定源代码是什么版本的,如果源码和这个版本不符将报错,Maven中执行编译的时候会用到这个配置,默认是1.5,这个相当于javac命令后面的-source参数 --><maven.compiler.source>1.8</maven.compiler.source><!-- 该命令用于指定生成的class文件将保证和哪个版本的虚拟机进行兼容,Maven中执行编译的时候会用到这个配置,默认是1.5,这个相当于javac命令后面的-target参数 --><maven.compiler.target>1.8</maven.compiler.target><maven-plugin-tools.version>3.13.1</maven-plugin-tools.version></properties><dependencies><dependency><groupId>org.apache.maven</groupId><artifactId>maven-plugin-api</artifactId><version>3.0</version><scope>provided</scope></dependency><!-- dependencies to annotations --><dependency><groupId>org.apache.maven.plugin-tools</groupId><artifactId>maven-plugin-annotations</artifactId><version>${maven-plugin-tools.version}</version><scope>provided</scope></dependency></dependencies><build><pluginManagement><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-plugin-plugin</artifactId><version>${maven-plugin-tools.version}</version><executions><execution><id>help-mojo</id><goals><!-- good practice is to generate help mojo for plugin --><goal>helpmojo</goal></goals></execution></executions></plugin></plugins></pluginManagement><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.13.0</version><configuration><source>8</source><target>8</target></configuration></plugin></plugins></build></project>
自动生成的 xml 版本:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>cn.myphoenix</groupId><artifactId>timer-maven-plugin</artifactId><version>1.0-SNAPSHOT</version><packaging>maven-plugin</packaging><name>timer-maven-plugin Maven Plugin</name><!-- FIXME change it to the project's website --><url>http://maven.apache.org</url><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><dependency><groupId>org.apache.maven</groupId><artifactId>maven-plugin-api</artifactId><version>2.0</version></dependency><dependency><groupId>org.apache.maven.plugin-tools</groupId><artifactId>maven-plugin-annotations</artifactId><version>3.2</version><scope>provided</scope></dependency><dependency><groupId>org.codehaus.plexus</groupId><artifactId>plexus-utils</artifactId><version>3.0.8</version></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.8.2</version><scope>test</scope></dependency></dependencies><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-plugin-plugin</artifactId><version>3.2</version><configuration><goalPrefix>timer-maven-plugin</goalPrefix><skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound></configuration><executions><execution><id>mojo-descriptor</id><goals><goal>descriptor</goal></goals></execution><execution><id>help-goal</id><goals><goal>helpmojo</goal></goals></execution></executions></plugin></plugins></build><profiles><profile><id>run-its</id><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-invoker-plugin</artifactId><version>1.7</version><configuration><debug>true</debug><cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo><pomIncludes><pomInclude>*/pom.xml</pomInclude></pomIncludes><postBuildHookScript>verify</postBuildHookScript><localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath><settingsFile>src/it/settings.xml</settingsFile><goals><goal>clean</goal><goal>test-compile</goal></goals></configuration><executions><execution><id>integration-test</id><goals><goal>install</goal><goal>integration-test</goal><goal>verify</goal></goals></execution></executions></plugin></plugins></build></profile></profiles> </project>
(3) 添加版本控制(可选)
将不需要版本控制的文件或文件夹添加到 .gitignore 中。
2、创建目标类Mojo
- Javadoc 注释设置目标的 description 为"时间提醒器",创建目标后会解析注释内容
- 使用 @Mojo 注解的 name 属性为目标设置名称 timer。
- 继承 AbstractMojo 抽象类,并重写 execute 方法。
package cn.myphoenix.timer;import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;import java.time.LocalDateTime;/*** 时间提醒器** @author: larry_lwh* @date: 2024-12-06 21:09* @description: 时间提醒 Mojo**/
@Mojo(name = "timer")
public class TimerMojo extends AbstractMojo {public void execute() throws MojoExecutionException, MojoFailureException {this.getLog().info("现在是北京时间:" + LocalDateTime.now());}
}
查看自定义目标的详细信息:mvn help:describe -Dplugin="cn.myphoenix:timer-maven-plugin"
(base) PS C:\...\maven_00> mvn help:describe -Dplugin="cn.myphoenix:timer-maven-plugin"
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< cn.myphoenix:maven_00 >------------------------
[INFO] Building maven_00 1.0-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-help-plugin:3.5.1:describe (default-cli) @ maven_00 ---
[INFO] cn.myphoenix:timer-maven-plugin:1.0-SNAPSHOTName: timer-maven-plugin Maven Plugin
Description: The Maven Timer Plugin is a plugin that displays the currenttime in the default timezone.
Group Id: cn.myphoenix
Artifact Id: timer-maven-plugin
Version: 1.0-SNAPSHOT
Goal Prefix: timerThis plugin has 2 goals:timer:helpDescription: Display help information on timer-maven-plugin. Call mvntimer:help -Ddetail=true -Dgoal= to display parameter details.timer:timerDescription: 时间提醒器For more information, run 'mvn help:describe [...] -Ddetail'[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.573 s
[INFO] Finished at: 2024-12-06T21:54:25+08:00
[INFO] ------------------------------------------------------------------------
3、打包插件,并安装到本地仓库
我们开发插件的目的就是本地项目或者其他开发人员要用,因此,需要将插件工程打包,并安装到本地仓库或部署到远程仓库(私服)。
在当前工程执行mvn clean install
,以将插件工程打包并安装到本地 Maven 仓库。当然也可以发布到 Nexus 私服。
控制台打印:
(base) PS C:\...\timer-maven-plugin> mvn clean install
[INFO] Scanning for projects...
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ timer-maven-plugin ---
[INFO] Deleting C:\Coding_Gallery\Intellij_IDEA_Workspace\timer-maven-plugin\target
[INFO]
[INFO] --- maven-plugin-plugin:3.13.1:helpmojo (help-mojo) @ timer-maven-plugin ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ timer-maven-plugin ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Coding_Gallery\Intellij_IDEA_Workspace\timer-maven-plugin\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.13.0:compile (default-compile) @ timer-maven-plugin ---
[INFO] Recompiling the module because of changed source code.
[INFO] Compiling 2 source files with javac [debug target 8] to target\classes
[INFO]
[INFO] --- maven-plugin-plugin:3.13.1:descriptor (default-descriptor) @ timer-maven-plugin ---
[INFO] Using 'UTF-8' encoding to read mojo source files.
[INFO] java-annotations mojo extractor found 2 mojo descriptors.
[INFO] java-javadoc mojo extractor found 0 mojo descriptor.
[INFO] ant mojo extractor found 0 mojo descriptor.
[INFO] bsh mojo extractor found 0 mojo descriptor.
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ timer-maven-plugin ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Coding_Gallery\Intellij_IDEA_Workspace\timer-maven-plugin\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.13.0:testCompile (default-testCompile) @ timer-maven-plugin ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ timer-maven-plugin ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ timer-maven-plugin ---
[INFO] Building jar: C:\Coding_Gallery\Intellij_IDEA_Workspace\timer-maven-plugin\target\timer-maven-plugin-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- maven-plugin-plugin:3.13.1:addPluginArtifactMetadata (default-addPluginArtifactMetadata) @ timer-maven-plugin ---
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ timer-maven-plugin ---
[INFO] Installing C:\Coding_Gallery\Intellij_IDEA_Workspace\timer-maven-plugin\target\timer-maven-plugin-1.0-SNAPSHOT.jar to C:\Softwares\Developer_Kits\apache-maven-3.8.8\repository\cn\myphoenix\timer-maven-plugin\1.0-SNAPSHOT\timer-maven-plugin-1.0-SNAPSHOT.jar
[INFO] Installing C:\Coding_Gallery\Intellij_IDEA_Workspace\timer-maven-plugin\pom.xml to C:\Softwares\Developer_Kits\apache-maven-3.8.8\repository\cn\myphoenix\timer-maven-plugin\1.0-SNAPSHOT\timer-maven-plugin-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.505 s
[INFO] Finished at: 2024-12-06T21:20:09+08:00
[INFO] ------------------------------------------------------------------------
可以看到,packaging 为 maven-plugin,打成的包也是 jar 包:timer-maven-plugin-1.0-SNAPSHOT.jar
4、运行插件
在其他任意一个项目的 pom 文件中引入自定义的 timer-maven-plugin 插件:
<build><plugins><plugin><groupId>cn.myphoenix</groupId><artifactId>timer-maven-plugin</artifactId><version>1.0-SNAPSHOT</version></plugin></plugins>
</build>
方式一
命令行直接执行插件mvn cn.myphoenix:timer-maven-plugin:timer
控制台打印如下:插件运行成功
(base) PS C:\...\maven_00> mvn cn.myphoenix:timer-maven-plugin:timer
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< cn.myphoenix:maven_00 >------------------------
[INFO] Building maven_00 1.0-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- timer-maven-plugin:1.0-SNAPSHOT:timer (default-cli) @ maven_00 ---
[INFO] 现在是北京时间:2024-12-06T21:25:50.739
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.226 s
[INFO] Finished at: 2024-12-06T21:25:50+08:00
[INFO] ------------------------------------------------------------------------
方式二:使用前缀名
我们自定义的插件是否也有前缀名?
使用 help 插件的 describe 目标查看一下我们自定义的 timer-maven-timer 插件的详细信息:
(base) PS C:\...\maven_00> mvn help:describe -Dplugin="cn.myphoenix:timer-maven-plugin"
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< cn.myphoenix:maven_00 >------------------------
[INFO] Building maven_00 1.0-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-help-plugin:3.5.1:describe (default-cli) @ maven_00 ---
[INFO] cn.myphoenix:timer-maven-plugin:1.0-SNAPSHOTName: timer-maven-plugin Maven Plugin
Description: (no description available)
Group Id: cn.myphoenix
Artifact Id: timer-maven-plugin
Version: 1.0-SNAPSHOT
Goal Prefix: timerThis plugin has 2 goals:timer:helpDescription: Display help information on timer-maven-plugin. Call mvntimer:help -Ddetail=true -Dgoal= to display parameter details.timer:timerDescription: (no description available)For more information, run 'mvn help:describe [...] -Ddetail'[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.603 s
[INFO] Finished at: 2024-12-06T21:28:54+08:00
[INFO] ------------------------------------------------------------------------
竟然有前缀名,可是我们并没有配置啊。
在 Maven 官网给出了插件命名规范:
You will typically name your plugin <yourplugin>-maven-plugin.
Calling it maven-<yourplugin>-plugin (note "Maven" is at the beginning of the plugin name) is strongly discouraged since it's a reserved naming pattern for official Apache Maven plugins maintained by the Apache Maven team with groupId org.apache.maven.plugins.
Using this naming pattern is an infringement of the Apache Maven Trademark.
也就是说,我们定义的格式只要遵循<name>-maven-plugin
或maven-<name>-plugin
,Maven 就会将 name 设置为插件的前缀名。我们一般使用前一种插件命名方式,因为后一种可能会侵权。
因此,将插件名设置为 timer-maven-plugin,Maven 会帮忙设置前缀名是 timer。
简化命令行:mvn timer:timer
(base) PS C:\...\maven_00> mvn timer:timer
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< cn.myphoenix:maven_00 >------------------------
[INFO] Building maven_00 1.0-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- timer-maven-plugin:1.0-SNAPSHOT:timer (default-cli) @ maven_00 ---
[INFO] 现在是北京时间:2024-12-06T21:35:49.901
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.185 s
[INFO] Finished at: 2024-12-06T21:35:49+08:00
[INFO] ------------------------------------------------------------------------
5、将插件目标绑定到生命周期阶段上(可选)
方式一:pom文件显式绑定(官方使用)
在引入自定义插件 timer-maven-pluging 的项目 pom 文件中,显式地将插件目标绑定到 default 生命周期的 validate 阶段:
<build><plugins><plugin><groupId>cn.myphoenix</groupId><artifactId>timer-maven-plugin</artifactId><version>1.0-SNAPSHOT</version><executions><execution><phase>validate</phase><id>default-timer</id><goals><goal>timer</goal></goals></execution></executions></plugin></plugins>
</build>
执行mvn validate
命令验证:绑定成功
(base) PS C:\Coding_Gallery\Intellij_IDEA_Workspace\maven_lifecycle_plugin_demo\maven_00> mvn validate
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< cn.myphoenix:maven_00 >------------------------
[INFO] Building maven_00 1.0-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- timer-maven-plugin:1.0-SNAPSHOT:timer (default-timer) @ maven_00 ---
[INFO] 现在是北京时间:2024-12-06T22:13:24.689
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.221 s
[INFO] Finished at: 2024-12-06T22:13:24+08:00
[INFO] ------------------------------------------------------------------------
方式二:@Mojo注解的defaultPhase属性执行
在 Mojo 类的 @Mojo 注解中使用 defaultPhase 属性绑定阶段
@Mojo(name = "timer", defaultPhase = LifecyclePhase.VALIDATE)
public class TimerMojo extends AbstractMojo {public void execute() throws MojoExecutionException, MojoFailureException {this.getLog().info("现在是北京时间:" + LocalDateTime.now());}
}
但是,使用这种方式需要在引入自定义插件 timer-maven-plugin 处使用 goal 标签,phase 标签可不指定。如果不指定 goal 标签,就无法绑定。pom 如下配置,@Mojo 注解的 defaultPhase 属性才会生效:
<build><plugins><plugin><groupId>cn.myphoenix</groupId><artifactId>timer-maven-plugin</artifactId><version>1.0-SNAPSHOT</version><executions><execution><id>default-timer</id><goals><goal>timer</goal></goals></execution></executions></plugin></plugins>
</build>
思考
我们在平时使用官方提供的插件,例如 maven-surefire-plugin 时好像并没有在 pom 文件中显式声明。而且,就算显式声明了,也不需要像方式二那样还要使用 executions -> execution -> goals -> goal。
演示 1:没有显式引入 maven-surefire-plugin 插件
如下所示,没有显式引入该插件,依然可以使用
(base) PS C:\...\maven_00> mvn clean
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< cn.myphoenix:maven_00 >------------------------
[INFO] Building maven_00 1.0-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ maven_00 ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.218 s
[INFO] Finished at: 2024-12-07T10:03:39+08:00
[INFO] ------------------------------------------------------------------------
演示二:显式引入 maven-surefire-plugin 插件,但不做任何配置
pom 文件配置如下:
<build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><version>3.5.0</version></plugin></plugins>
</build>
运行结果如下:
可以看到,即使没有做任何配置,如显式声明 goal 标签,我们依旧可以成功执行插件目标。
(base) PS C:\...\maven_00> mvn clean
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< cn.myphoenix:maven_00 >------------------------
[INFO] Building maven_00 1.0-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ maven_00 ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.193 s
[INFO] Finished at: 2024-12-07T10:06:24+08:00
[INFO] ------------------------------------------------------------------------
所以,为什么会这样呢?自定义插件需要显式声明 goal,而官方插件就不需要显式声明 goal。
这是因为 Maven 硬编码了一些插件目标和生命周期阶段的绑定,我们自己项目的 pom 文件会继承这些硬编码的绑定,例如 maven-clean-plugin 的 clean 目标和 clean 生命周期的 clean 阶段已经绑定了,我们直接用就行。
然而,我们自定义的插件并没有硬编码式的绑定到某些阶段上,所以,在引入插件时,需要在 pom 文件中显式地将其目标绑定到阶段上。
总结:
在将官方插件目标或自定义插件目标绑定到某个阶段上时,需要我们在引入插件时显式地声明插件和目标的绑定,也就是方式一。
6、参数设置
平时我们在将本地项目打包安装到本地仓库或打包部署到私服上时,会执行如下命令:
# 打包并安装到本地仓库
mvn clean install -DskipTests=true# 打包并部署到私服
mvn clean deploy -DskipTests=true
观察到,有一个参数配置 -DskipTests=true。这个参数配置是哪里来的呢?
我们可以顺藤摸瓜,既然我们执行的是插件目标,而目标又是一个 Mojo 类,那参数应该是类中的属性吧?
这个猜测是正确的,上面命令行中配置的参数的确是 Mojo 类的属性。我们配置参数,实际上就是为属性赋值。
之前提到了查看目标参数的命令,我们不妨查看一下 maven-clean-plugin:clean 的目标类的属性。
结果如下:
(base) PS C:\...\maven_00> mvn clean:help -Dgoal=clean -Ddetail
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< cn.myphoenix:maven_00 >------------------------
[INFO] Building maven_00 1.0-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:help (default-cli) @ maven_00 ---
[INFO] org.apache.maven.plugins:maven-clean-plugin:2.5Maven Clean PluginThe Maven Clean Plugin is a plugin that removes files generated at build-timein a project's directory.clean:cleanGoal which cleans the build.This attempts to clean a project's working directory of the files that weregenerated at build-time. By default, it discovers and deletes the directoriesconfigured in project.build.directory, project.build.outputDirectory,project.build.testOutputDirectory, and project.reporting.outputDirectory.Files outside the default may also be included in the deletion by configuringthe filesets tag.Available parameters:excludeDefaultDirectories (Default: false)Disables the deletion of the default output directories configured for aproject. If set to true, only the files/directories selected via theparameter filesets will be deleted.Expression: ${clean.excludeDefaultDirectories}failOnError (Default: true)Indicates whether the build will continue even if there are clean errors.Expression: ${maven.clean.failOnError}filesetsThe list of file sets to delete, in addition to the default directories.For example:<filesets><fileset><directory>src/main/generated</directory><followSymlinks>false</followSymlinks><useDefaultExcludes>true</useDefaultExcludes><includes><include>*.java</include></includes><excludes><exclude>Template*</exclude></excludes></fileset></filesets>followSymLinks (Default: false)Sets whether the plugin should follow symbolic links while deleting filesfrom the default output directories of the project. Not following symlinksrequires more IO operations and heap memory, regardless whether symlinksare actually present. So projects with a huge output directory thatknowingly does not contain symlinks can improve performance by settingthis parameter to true.Expression: ${clean.followSymLinks}retryOnError (Default: true)Indicates whether the plugin should undertake additional attempts (after ashort delay) to delete a file if the first attempt failed. This is meantto help deleting files that are temporarily locked by third-party toolslike virus scanners or search indexing.Expression: ${maven.clean.retryOnError}skip (Default: false)Disables the plugin execution.Expression: ${clean.skip}verboseSets whether the plugin runs in verbose mode. As of plugin version 2.3,the default value is derived from Maven's global debug flag (comparecommand line switch -X).Expression: ${clean.verbose}[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.213 s
[INFO] Finished at: 2024-12-07T10:48:27+08:00
[INFO] ------------------------------------------------------------------------
可以看到,maven-clean-plugin 的 clean 目标有丰富的参数。
我们在自定义插件时也可以为 Mojo 类指定参数,以丰富插件的功能。
实现
例如,我们在 timer-maven-plugin 插件的 timer 目标类中定义如下属性:
/*** 时间提醒器***/
@Mojo(name = "timer", defaultPhase = LifecyclePhase.VALIDATE)
public class TimerMojo extends AbstractMojo {/*** timeType = dateTime,则控制台显式日期时间* timeType = date,则控制台只显示日期*/@Parameter(property = "timeType", defaultValue = "dateTime")private String timeType;public void execute() throws MojoExecutionException, MojoFailureException {if ("dateTime".equals(timeType)) {this.getLog().info("现在是北京时间:" + LocalDateTime.now());} else if ("date".equals(timeType)) {this.getLog().info("现在是:" + LocalDate.now());} else {this.getLog().info("现在是北京时间:" + LocalDateTime.now());}}
}
演示:同上,已经将 timer 目标绑定到 validate 阶段
(1) 执行命令mvn validate -DtimeType=date
,结果如下
(base) PS C:\...\maven_00> mvn validate -DtimeType=date
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< cn.myphoenix:maven_00 >------------------------
[INFO] Building maven_00 1.0-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- timer-maven-plugin:1.0-SNAPSHOT:timer (default-timer) @ maven_00 ---
[INFO] 现在是:2024-12-07
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.214 s
[INFO] Finished at: 2024-12-07T11:04:07+08:00
[INFO] ------------------------------------------------------------------------
(2) 执行命令mvn validate -DtimeType=date
,结果如下
(base) PS C:\...\maven_00> mvn validate -DtimeType=dateTime
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< cn.myphoenix:maven_00 >------------------------
[INFO] Building maven_00 1.0-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- timer-maven-plugin:1.0-SNAPSHOT:timer (default-timer) @ maven_00 ---
[INFO] 现在是北京时间:2024-12-07T11:07:02.601
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.189 s
[INFO] Finished at: 2024-12-07T11:07:02+08:00
[INFO] ------------------------------------------------------------------------
如上所示,通过在命令行中给属性 timeType 赋不同的值,可以执行不同的逻辑。
因此,在开发插件时,我们通常也会给目标 Mojo 设置属性值。
相关文章:
【Maven】自定义Maven插件
场景: 1、自定义一个插件目标 timer,用于显示当前日期时间。 2、将 timer 绑定到 validate 阶段。 调研 1、maven-clean-plugin 下载 maven-clean-plugin 插件的源码,在本地使用 IDEA 打开 可以看到,maven-clean-plugin 插件是…...
修改vscode中emmet中jsx和tsx语法中className的扩展符号从单引号到双引号 - HTML代码补全 - 单引号双引号
效果图 实现步骤 文件 > 首选项 > 设置搜索“”在settings.json中修改,增加 "emmet.syntaxProfiles": {"html": {"attr_quotes": "single"},"jsx": {"attr_quotes": "double","…...
数据结构day3作业
一、完整功能【顺序表】的创建 【seqList.h】 #ifndef __SEQLIST_H__ #define __SEQLIST_H__#include <stdio.h> #include <string.h> #include <stdlib.h>//宏定义,线性表的最大容量 #define MAX 30//类型重定义,表示要存放数据的类…...
pydub AudioSegment实现音频重采样 - python 实现
DataBall 助力快速掌握数据集的信息和使用方式,会员享有 百种数据集,持续增加中。 需要更多数据资源和技术解决方案,知识星球: “DataBall - X 数据球(free)” -------------------------------------------------------------…...
C++多线程常用方法
在 C 中,线程相关功能主要通过头文件提供的类和函数来实现,以下是一些常用的线程接口方法和使用技巧: std::thread类 构造函数: 可以通过传入可调用对象(如函数指针、函数对象、lambda 表达式等)来创建一…...
【网络安全】Web Timing 和竞争条件攻击:揭开隐藏的攻击面
Web Timing 和竞争条件攻击:揭开隐藏的攻击面 在传统的 Web 应用中,漏洞的发现和利用通常相对容易理解。如果代码存在问题,我们可以通过发送特定输入来强制 Web 应用执行非预期的操作。这种情况下,输入和输出之间往往有直接关系&…...
12月最新编程语言排行榜
“岁末将至,2024年的编程世界又发生了哪些变化?是Python依然稳坐王座,还是有新语言杀出重围?让我们一起看看12月最新编程语言排行榜,寻找未来技术的风向标。” 今年,哪些编程语言成为行业焦点?…...
迭代器模式
迭代器模式 迭代器模式(Iterator Pattern)是一种行为设计模式,它提供了一种方法来访问一个聚合对象中的各个元素,而又不暴露其内部的表示。这种模式允许你逐个访问对象中的元素,而无需知道其底层的数据结构。迭代器模…...
探秘 WB 实验:AI 助力攻克操作难关
在生物学研究的浩瀚领域中,WB 实验犹如一座关键的灯塔,照亮了我们探索蛋白质世界的道路。今天,就让我们一同深入了解 WB 实验的全貌,以及 AI 如何在其中发挥神奇作用,帮助我们应对实际操作中的重重挑战。 WB 实验&…...
labelimg使用指南
YOLOv8目标检测(一)_检测流程梳理:YOLOv8目标检测(一)_检测流程梳理_yolo检测流程-CSDN博客 YOLOv8目标检测(二)_准备数据集:YOLOv8目标检测(二)_准备数据集_yolov8 数据集准备-CSDN博客 YOLOv8目标检测(三)_训练模型:YOLOv8目标检测(三)_训…...
车载终端_智能车载终端定制_农机/出租车/叉车/驾培车载终端MTK方案
车载终端集成了先进的技术和卓越的性能,采用了联发科的高效低功耗ARM处理器,具备八核架构,主频高达2.0GHz,基于12nm制程工艺,不仅性能强劲,而且功耗控制出色。基本配置为4GB内存与64GB存储,用户…...
Unity中Pico实现透视
1.参照Pico官方【透视 | PICO 开发者平台】文档设置。 2.额外的需要将主相机的post processing禁用。...
elk部署与实战案例
**ELK Stack** 是一个非常强大的日志处理和分析平台,由 **Elasticsearch**、**Logstash** 和 **Kibana** 三个组件组成。它被广泛应用于日志收集、搜索、分析和可视化。ELK 可以处理大量数据,并帮助用户从中提取有价值的信息。以下是一个从部署到实际应用…...
Isaac Gym, Sim, Lab
本文仅为个人学习笔记,文章参考请见参考资料部分,主要目的是进行多场景并行仿真测试,笔记中大部分内容都是针对于这个目标。 参考资料 常见问题 — Isaac Lab 文档 https://github.com/isaac-sim/IsaacLab 一. Gym, Sim, Lab 之间的关系 Is…...
活着就好20241217
亲爱的朋友们,大家早上好!🌞 今天是17号,星期二,2024年12月的第十七天,同时也是第50周的第八天,农历甲辰[龙]年十一月初十三日。在这晨光熹微的美好时刻,愿那温暖而明媚的阳光轻轻拂…...
第十六章:IO流 (java.io包中)
一、理解 1. 简单而言:流就是内存与存储设备之间传输数据的通道、管道。 2. 分类: (1) 按方向 ( 以 JVM 虚拟机为参照物 ) 【重点】 输入流:将 < 存储设备 > 中的内容读入到 < 内存 > 中。 输出流:将 < 内…...
Introduction to NoSQL Systems
What is NoSQL NoSQL database are no-tabular非數據表格 database that store data differently than relational tables 其數據的存儲方式與關係型表格不同 Database that provide a mechanism機制 for data storage retrieval 檢索 that is modelled in means other than …...
【JVM】JVM基础教程(四)
上一章:【JVM】JVM基础教程(三)-CSDN博客 目录 自动垃圾回收 方法区的回收 方法区回收条件 手动触发回收 堆回收 如何判断堆上的对象可以回收? 可以给对象引用赋值null,切断引用 引用计数法 循环引用缺点 查…...
前端实现在线预览excel文件
在前端开发中,经常会遇到需要在线预览各种文件的需求。本文将介绍如何使用前端技术实现在线预览 Excel 文件的功能。 一、基于微软office服务的excel预览 获取要预览的 Excel 文件的 URL(例如存储在 OneDrive 或 SharePoint 上的文件)。 使…...
Python 写的《桌面时钟》屏保
原代码: # 日历式时钟 # 导入所需的库 # 作者:Hoye # 日期:2024年12月16日 # 功能:显示当前日期、星期、时间,并显示模拟时钟 import tkinter as tk from tkinter import ttk import time import math import sysdef …...
计算机视觉单阶段实例分割实践指南与综述
概述 原文地址:https://towardsdatascience.com/single-stage-instance-segmentation-a-review-1eeb66e0cc49 实例分割是一项具有挑战性的计算机视觉任务,需要预测对象实例及其每像素分割掩码。这使其成为语义分割和目标检测的混合体。 自 Mask R-CNN …...
Axios结合Typescript 二次封装完整详细场景使用案例
Axios 是一个基于 promise 的 HTTP 客户端,用于浏览器和 node.js。二次封装 Axios 主要是为了统一管理 HTTP 请求,例如设置统一的请求前缀、头部、超时时间,统一处理请求和响应的格式,以及错误处理等。 以下是一个使用 TypeScrip…...
C++面试:HTTP1.0/1.1,HTTP2.0,HTPP3.0的区别
1.你对HTTP1.0/1.1,HTTP2.0,HTPP3.0有什么了解? 答:HTTP1.0: ①属于无连接式,每次发送HTTP请求都需要建立TCP连接。 ②会造成发送时的对头阻塞,当上一个请求没有应答,当前的请求就会…...
使用 Docker Compose 部署 Redis 主从与 Sentinel 高可用集群
文章目录 使用 Docker Compose 部署 Redis 主从与 Sentinel 高可用集群Redis 主从架构简介Redis Sentinel 简介配置文件1. 主节点配置 (redis-master.conf)2. 从节点配置 (redis-slave1.conf 和 redis-slave2.conf)redis-slave1.confredis-slave2.conf3. Sentinel 配置 (sentin…...
【Java】4、虚拟机 JVM
目录 Java内存区域详解(重点) JVM垃圾回收详解(重点) 类文件结构详解 类加载过程详解 类加载器详解(重点) 最重要的JVM参数总结 JDK监控和故障处理工具总结 JVM线上问题排查和性能调优案例 参考: JVM 核心技术 32 讲 深入浅出 Java 虚拟机...
Vue3之组合式API详解
Vue 3引入了一种新的API风格——组合式API(Composition API),旨在提升组件的逻辑复用性和可维护性。本文将详细阐述Vue 3中的组合式API,包括其定义、特点、使用场景、优势等,并给出具体的示例代码。 一、定义 组合式…...
Flutter编译Module was compiled with an incompatible version of Kotlin错误解决
文章目录 编译报错如下解决方法修复方案 编译报错如下 e: C:/Users/YUAN/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.9.20/e58b4816ac517e9cc5df1db051120c63d4cde669/kotlin-stdlib-1.9 .20.jar!/META-INF/kotlin-stdlib-jdk8.kotlin_module:…...
Uniapp插件如何通过NFC读取多种证卡信息?
nfc读卡uniapp插件,由中软高科进行开发,主要是通过NFC读取居民身份证、港澳台居住证、外国人居住证、护照等证卡的信息。经过多个版本的升级更新,目前性能已趋于稳定,并且读卡速度较之最初版本有了大的提升。 注意事项 测试使用的…...
本地docker镜像改名字
如果你想修改本地 Docker 镜像的名字,可以通过创建该镜像的新标签(tag)来实现。Docker 中没有直接修改镜像名字的命令,但可以通过重新打标签的方式实现类似的效果。以下是具体步骤: 查看当前镜像: docker…...
VS Code 远程连接 SSH 服务器
文章目录 一、安装 Remote - SSH 扩展并连接远程主机二、免密连接远程主机1. 生成 SSH 密钥对2. 将公钥复制到远程服务器3. 配置 SSH 客服端4. 连接测试 随着技术的不断迭代更新,在 Linux 系统中使用 Vim、nano 等基于 Shell 终端的编辑器(我曾经也是个 …...
艾体宝案例丨CircleCI 助力 ANA Systems 打造高效 CI/CD 模型
在现代软件开发领域,效率和可靠性是企业在竞争中取胜的关键。本文将深入探讨 ANA Systems 如何通过引入业界领先的 CI/CD 平台——CircleCI,克服传统开发流程的瓶颈,实现开发运营效率的全面提升。同时,本文还将详细解析 CircleCI …...
vue 上传组件 vxe-upload 实现拖拽调整顺序
vue 上传组件 vxe-upload 实现拖拽调整顺序,通过设置 drag-sort 参数就可以启用拖拽排序功能 官网:https://vxeui.com/ 图片拖拽排序 <template><div><vxe-upload v-model"imgList" mode"image" multiple drag-sor…...
Elasticsearch的一些介绍
你想问的可能是 **Elasticsearch**,以下是关于它的一些介绍: ### 概述 Elasticsearch是一个基于Apache Lucene库构建的开源分布式搜索和分析引擎,采用Java语言编写,具有高性能、可扩展性和易用性等特点,可用于各种数据…...
从源码构建安装Landoop kafka-connect-ui
背景 部署Landoop kafka-connect-ui最简单的办法还是通过docker来部署,我们之前的kafka-connect-ui就是通过docker部署的,但是,最近发现个问题:当使用docker部署且防火墙使用的是firewalld的情况下,就会出现端口冲突。…...
MybatisPlus-扩展功能
代码生成 在使用MybatisPlus以后,基础的Mapper、Service、PO代码相对固定,重复编写也比较麻烦。因此MybatisPlus官方提供了代码生成器根据数据库表结构生成PO、Mapper、Service等相关代码。只不过代码生成器同样要编码使用,也很麻烦。 这里…...
发布/部署WebApi服务器(IIS+.NET8+ASP.NETCore)
CS软件授权注册系统-发布/部署WebApi服务器(IIS.NET8ASP.NETCore) 目录 本文摘要VS2022配置发布VS2022发布WebApiIIS服务器部署WebApi 将程序文件复制到云服务器添加网站配置应用程序池配置dns域名配置端口阿里云ECS服务器配置19980端口配置https协议 (申请ssl证书)测试WebAp…...
【2025最新计算机毕业设计】基于SpringBoot+Vue城市中小学体育场馆预约系统【提供源码+答辩PPT+文档+项目部署】
一、项目技术架构: 本项目是一款城市中小学体育场馆预约系统的设计与实现。 该SpringBootVue的城市中小学体育场馆预约系统,后端采用SpringBoot架构,前端采用VueElementUI实现页面的快速开发,并使用关系型数据库MySQL存储系统运行…...
Spring Security 6 系列之二 - 基于数据库的用户认证和认证原理
之所以想写这一系列,是因为之前工作过程中使用Spring Security,但当时基于spring-boot 2.3.x,其默认的Spring Security是5.3.x。之后新项目升级到了spring-boot 3.3.0,结果一看Spring Security也升级为6.3.0,关键是其风…...
vue中打包dist文件内static 和 assets 的区别
背景 在Vue.js项目中,assets 和 static 是两个用于存放静态资源的文件夹,但它们在使用方式和处理机制上有所不同 用途 assets: assets 文件夹通常用于存放那些需要在构建过程中被Webpack处理的静态资源。这些资源可以包括图片、字体、样式文件&#…...
Big Model weekly | 第49期
点击蓝字 关注我们 AI TIME欢迎每一位AI爱好者的加入! 01 Magnetic Preference Optimization: Achieving Last-iterate Convergence for Language Models Alignment 自我对弈方法在多个领域增强模型能力方面展现出了显著的成功。在基于人类反馈的强化学习࿰…...
Node.js内置模块
1.内置模块 Node.js的中文网参考手册:https://nodejs.cn//api 帮助文档 API文档:查看对应的模块,左边是模块,右边是模块的成员 源码:https://github.com/nodejs/node/tree/main/lib 查看 例如: http.js 创建web服务器的模块 -->进入源码中,搜索…...
使用Nexus3搭建npm私有仓库
一、npm介绍 npm的全称是Node Package Manager,它是一个开放源代码的命令行工具,用于安装、更新和管理Node.js模块。npm是Node.js的官方模块管理器,它允许用户从一个集中的仓库中下载和安装公共的Node.js模块,并将这些模块集成到…...
MySQL学习之表操作
MySQL学习之表操作 基础命令 查询当前所在数据库的所有表 show tables;查看指定的表结构, 可以查看到指定表的字段,字段的类型、是否可以为NULL,是否存在默认值等信息 mysql> desc user; ----------------------------------------------- | Field |…...
C语言学习day22:ReadProcessMemory函数/游戏内存数据读取工具开发
简言: ReadProcessMemory函数是 Windows API 中的一个函数,用于从目标进程的虚拟内存空间中读取数据。这个函数非常有用,尤其是在进行内存分析、调试、或某些类型的逆向工程时。 ReadProcessMemory函数 函数原型 BOOL ReadProcessMemory(…...
Linux虚拟文件系统
参考:深入分析LINUX内核源码 深入分析Linux内核源码 (kerneltravel.net) 作为一个最著名的自由软件,Linux 确实名不虚传,几乎处处体现了“自由”,你可以编译适合自己系统要求的内核,或者轻松添加别人开发的新的模块。只…...
OpenIPC开源FPV之Adaptive-Link天空端代码解析
OpenIPC开源FPV之Adaptive-Link天空端代码解析 1. 源由2. 框架代码3. 报文处理3.1 special报文3.2 普通报文 4. 工作流程4.1 Profile 竞选4.2 Profile 研判4.3 Profile 应用 5. 总结6. 参考资料7. 补充资料7.1 RSSI 和 SNR 的物理含义7.2 信号质量加权的理论依据7.3 实际应用中…...
NPU是什么?电脑NPU和CPU、GPU区别介绍
随着人工智能技术的飞速发展,计算机硬件架构也在不断演进以适应日益复杂的AI应用场景。其中,NPU(Neural Processing Unit,神经网络处理器)作为一种专为深度学习和神经网络运算设计的新型处理器,正逐渐崭露头…...
.Net WebAPI(一)
文章目录 项目地址一、WebAPI基础1. 项目初始化1.1 创建简单的API1.1.1 get请求1.1.2 post请求1.1.3 put请求1.1.4 Delete请求 1.2 webapi的流程 2.Controllers2.1 创建一个shirts的Controller 3. Routing3.1 使用和创建MapControllers3.2 使用Routing的模板语言 4. Mould Bind…...
.NET 技术 | 调用系统API创建Windows服务
01阅读须知 此文所提供的信息只为网络安全人员对自己所负责的网站、服务器等(包括但不限于)进行检测或维护参考,未经授权请勿利用文章中的技术资料对任何计算机系统进行入侵操作。利用此文所提供的信息而造成的直接或间接后果和损失…...
OpenLinkSaas 2025年1月开发计划
先来看看OpenLinkSaas的大目标 在OpenLinkSaas的产品目标中,让开发人员更加方便的使用云资源是目标之一。通过各大云厂商的API,来可视化云上基础设施的数据是远远不够的。我们准备在2025年1月份增加方便管理和运营研发场景下服务器的能力。 这部分的功能…...