<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[Heck's  Blog]]></title> 
<link>https://www.heckjj.com/index.php</link> 
<description><![CDATA[一瞬间的决定，往往可以改变很多，事实上，让自己成功的往往不是知识，是精神！ 如果你总是为自己找借口，那只好让成功推迟。执行力，今天！]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[Heck's  Blog]]></copyright>
<item>
<link>https://www.heckjj.com/post//</link>
<title><![CDATA[maven创建自定义Archetype项目骨架]]></title> 
<author>Heck &lt;@hecks.tk&gt;</author>
<category><![CDATA[编程杂谈]]></category>
<pubDate>Sun, 27 Nov 2022 12:51:22 +0000</pubDate> 
<guid>https://www.heckjj.com/post//</guid> 
<description>
<![CDATA[ 
	Archetype是用于创建项目的骨架（或者模板），通过Archetype我们可以创建类似的Maven工程，同时Archetype能够极大的简化我们创建一个工程的步骤和流程。这里我将介绍自定义Maven的工程模板Archetype的方法和流程，这里采用的方法是从现有工程创建工程模板。<br/><br/>关于Archetype介绍参考：<a href="https://maven.apache.org/guides/introduction/introduction-to-archetypes.html" target="_blank">Introduction to Archetypes</a> <br/><br/>一、Archetype自定义流程：<br/>1、创建模板工程：找到一个现有的项目，进行编辑，将项目中的包结构、各类文件放置到合适的位置；<br/><br/><br/><br/>2、从模板工程创建Archetype：打开cmd窗口，切换当前目录到上面的工程目录下，执行maven命令：<br/><br/>mvn archetype:create-from-project<br/>执行完成后，target/generated-sourced/archetype目录下就是我们需要的项目模板。<br/><br/>3、安装Archetype到本地仓库：cd进入target/generated-sourced/archetype中，执行命令：<br/><br/>mvn -Dmaven.test.skip=true clean install<br/>将自定义Archetype安装到本地仓库即可：此时，自定义archetype就被安装到settings.xml中&lt;localRepository&gt;指定的本地仓库中，我的机器本地目录是D:/q/repos-maven；另外，archetype安装到本地仓库后，会在.m2/archetype-catalog.xml中加入对应的archetype节点，结构如下：<br/><br/>&lt;archetype&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;groupId&gt;com.heckjj.blog&lt;/groupId&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;artifactId&gt;crm-archetype-archetype&lt;/artifactId&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;version&gt;1.0.0&lt;/version&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;description&gt;The parent pom of crm&lt;/description&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/archetype&gt;<br/><br/> <br/><br/>4、使用自定义Archetype创建工程:<br/><br/>这样我们就创建成功了自定义的Archetype，可以通过命令从本地模板创建工程：<br/><br/>mvn archetype:generate -DarchetypeCatalog=local<br/>以上就是创建自定义Archetype的简单流程。<br/><br/><br/>如果以上自动生成的Archetype包含了一些不必要的文件，则可以继续对工程进行编辑，并且修改工程描述文件：/target/generated-sources/archetype/target/classes/META-INF/maven/archetype-metadata.xml<br/><br/>二、模板工程描述文件自定义<br/>如果希望继续自定义，可以在一中执行了mvn archetype:create-from-project命令后，生成的目录中，编辑archetype-metadata.xml，删除无用文件等，然后在mvn install安装到本地目录。archetype-metadata.xml保存在：/target/generated-sources/archetype/target/classes/META-INF/maven/archetype-metadata.xml，该文件主要用于描述需要生成的工程的结构和文件等，其描述规则参考Maven官方文档：<a href="https://maven.apache.org/archetype/archetype-models/archetype-descriptor/archetype-descriptor.html" target="_blank">ArchetypeDescriptor</a><br/> <br/><br/>如下是我的工程定义描述：<br/><br/>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br/>&lt;archetype-descriptor xsi:schemaLocation=&quot;http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd&quot; name=&quot;crm-360-evalution&quot;<br/>&nbsp;&nbsp;&nbsp;&nbsp;xmlns=&quot;http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0&quot;<br/>&nbsp;&nbsp;&nbsp;&nbsp;xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&gt;<br/>&nbsp;&nbsp;&lt;modules&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;module id=&quot;$&#123;rootArtifactId&#125;-common&quot; dir=&quot;__rootArtifactId__-common&quot; name=&quot;$&#123;rootArtifactId&#125;-common&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;fileSets&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;fileSet filtered=&quot;true&quot; encoding=&quot;UTF-8&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;directory&gt;src/main/java&lt;/directory&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;includes&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;include&gt;&lt;/include&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/includes&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/fileSet&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/fileSets&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/module&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;module id=&quot;$&#123;rootArtifactId&#125;-model&quot; dir=&quot;__rootArtifactId__-model&quot; name=&quot;$&#123;rootArtifactId&#125;-model&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;……<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/module&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;module id=&quot;$&#123;rootArtifactId&#125;-dao&quot; dir=&quot;__rootArtifactId__-dao&quot; name=&quot;$&#123;rootArtifactId&#125;-dao&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;fileSets&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;fileSet filtered=&quot;true&quot; encoding=&quot;UTF-8&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;directory&gt;src/main/java&lt;/directory&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;includes&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;include&gt;&lt;/include&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/includes&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/fileSet&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;fileSet encoding=&quot;UTF-8&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;directory&gt;src/resources&lt;/directory&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;includes&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;include&gt;**/*.xml&lt;/include&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;include&gt;**/*.properties&lt;/include&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/includes&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/fileSet&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/fileSets&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/module&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;module id=&quot;$&#123;rootArtifactId&#125;-service&quot; dir=&quot;__rootArtifactId__-service&quot; name=&quot;$&#123;rootArtifactId&#125;-service&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;……<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/module&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;module id=&quot;$&#123;rootArtifactId&#125;-main&quot; dir=&quot;__rootArtifactId__-main&quot; name=&quot;$&#123;rootArtifactId&#125;-main&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;fileSets&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;fileSet filtered=&quot;true&quot; encoding=&quot;UTF-8&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;directory&gt;src/main/java&lt;/directory&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;includes&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;include&gt;&lt;/include&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/includes&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/fileSet&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;fileSet filtered=&quot;true&quot; encoding=&quot;UTF-8&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;directory&gt;src/main/webapp&lt;/directory&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;includes&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;include&gt;**/*.vm&lt;/include&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;include&gt;**/*.jsp&lt;/include&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;include&gt;**/*.xml&lt;/include&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;include&gt;**/*.html&lt;/include&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/includes&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/fileSet&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;fileSet filtered=&quot;true&quot; encoding=&quot;UTF-8&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;directory&gt;src/main/resources&lt;/directory&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;includes&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;include&gt;**/*.xml&lt;/include&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;include&gt;**/*.properties&lt;/include&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/includes&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/fileSet&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;fileSet filtered=&quot;true&quot; encoding=&quot;UTF-8&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;directory&gt;src/main/profiles&lt;/directory&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;includes&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;include&gt;**/*.xml&lt;/include&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;include&gt;**/*.properties&lt;/include&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/includes&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/fileSet&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/fileSets&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/module&gt;<br/>&nbsp;&nbsp;&lt;/modules&gt;<br/>&lt;/archetype-descriptor&gt;<br/><br/>1、属性变量定义<br/><br/>$&#123;rootArtifactId&#125;在创建新的工程时，会根据定义的新工程的artifactId进行替换，将$&#123;rootArtifactId&#125;替换为artifactId。<br/>2、项目子模块定义<br/><br/>属于可选部分，在定义父子工程的时候才需要，描述了多个工程中包含的不同目录和文件。module主要由以下属性：<br/><br/>id：相当于工程的artifactId.<br/>dir：相当于工程源文件在archetype-resources里对应的directory.<br/>name：模块的名字.<br/><br/><br/>&lt;modules&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;module id=&quot;$&#123;rootArtifactId&#125;-model&quot; dir=&quot;__rootArtifactId__-model&quot; name=&quot;$&#123;rootArtifactId&#125;-model&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp; ……<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/module&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;module id=&quot;$&#123;rootArtifactId&#125;-dao&quot; dir=&quot;__rootArtifactId__-dao&quot; name=&quot;$&#123;rootArtifactId&#125;-dao&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;……<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/module&gt;<br/>&lt;modules&gt;<br/><br/>3、文件集定义<br/><br/>fileSets：包含的文件集；<br/><br/>fileSet：包含的文件；<br/><br/>director：目录；<br/><br/>includes：包含的具体文件或者文件类型；<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;fileSets&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;fileSet filtered=&quot;true&quot; encoding=&quot;UTF-8&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;directory&gt;src/main/java&lt;/directory&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;includes&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;include&gt;&lt;/include&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/includes&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/fileSet&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/fileSets&gt;
]]>
</description>
</item><item>
<link>https://www.heckjj.com/post//#blogcomment</link>
<title><![CDATA[[评论] maven创建自定义Archetype项目骨架]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>https://www.heckjj.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>