`
louisling
  • 浏览: 143058 次
  • 性别: Icon_minigender_1
  • 来自: ZhuHai
社区版块
存档分类
最新评论

创建 maven 插件

阅读更多
创建 maven 插件:

删除所有资源文件夹 mac 目录下面所有 grf 文件(target/classes/mac/**/*.grf)里面的内容:
<Property fileURL="src/main/resources/workspace.prm" id="GraphParameter0"/>
<Property fileURL="src/main/resources/workspace.prm" id="GraphParameter1"/>
<Property fileURL="src/main/resources/workspace.prm" id="GraphParameter2"/>


1)
cd/d C:\Temp
mvn archetype:create -DgroupId=org.xmlasia.plugins -DartifactId=edit-resource-maven-plugin -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-mojo

2)
EditResourceMojo.java

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Arrays;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;

/**
 * Goal which edit resource, remove specified line.
 * 
 * @goal editResource
 * @phase compile
 */
public class EditResourceMojo extends AbstractMojo {
    /**
     * @parameter
     */
    private File file;

    /**
     * @parameter
     */
    private String[] commentStrs;

    public File getFile() {
        return file;
    }

    public void setFile(File file) {
        this.file = file;
    }

    public String[] getCommentStr() {
        return commentStrs;
    }

    public void setCommentStr(String[] commentStrs) {
        this.commentStrs = commentStrs;
    }

    public void execute() throws MojoExecutionException {
        String absolutePath = file.getAbsolutePath();

        getLog().info("Edit resource: " + absolutePath + ": " + Arrays.toString(commentStrs) + ": " + file.exists());
        if (!file.exists()) {
            //Process folder
            if (absolutePath.contains("**\\*.")) {
                int index = absolutePath.lastIndexOf(".");
                String extension = absolutePath.substring(index + 1, absolutePath.length());

                index = absolutePath.indexOf("**\\*.");
                String path = absolutePath.substring(0, index);

                getLog().info("path: " + path + " extension: " + extension);

                File mFile = new File(path);
                getLog().info("Path exist: " + mFile.exists());

                for (String commentStr : commentStrs) {
                    try {
                        FileUtils.delContent(commentStr, path, extension);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        } else
            //Process single file
            editResources(file);
    }

    private void editResources(File mFile) {
        try {
            BufferedInputStream bin = new BufferedInputStream(new FileInputStream(mFile));
            byte[] buff = new byte[((int) mFile.length())];
            bin.read(buff);
            String str = new String(buff, "utf-8");
            String[] all = str.split("\r\n");
            int i = 0;

            OutputStream fout = new FileOutputStream(mFile);

            while (i < all.length) {
                for (String commentStr : commentStrs) {
                    all[i] = all[i].replaceAll(commentStr, "");
                }
                fout.write((all[i] + "\r\n").getBytes("utf-8"));
                i++;
            }
            fout.flush();
            fout.close();
            bin.close();
        } catch (Exception er) {
            er.printStackTrace();
        }
    }
}

3) 安装插件
mvn -Dmaven.test.skip=true install

4) 使用,在工程 pom.xml 加入如下内容:
   将 < > " 用转义字符替换掉。

	<build>
		<resources>
			<resource>
				<directory>${basedir}</directory>
				<includes>
					<include>mac/**/*.*</include>
				</includes>
			</resource>
            
			<resource>
                <directory>src/main/resources</directory>                
			</resource>
		</resources>
                
        <plugins>
              <plugin>
                <groupId>org.xmlasia.plugins</groupId>
                <artifactId>edit-resource-maven-plugin</artifactId>
                <version>1.0-SNAPSHOT</version>
                  
                <configuration>
                    <file>target/classes/mac/**/*.grf</file>
                    <commentStrs>
                        <param>&lt;Property fileURL=&quot;src/main/resources/workspace.prm&quot; id=&quot;GraphParameter0&quot;/&gt;</param>
                        <param>&lt;Property fileURL=&quot;src/main/resources/workspace.prm&quot; id=&quot;GraphParameter1&quot;/&gt;</param>
                    </commentStrs>
                </configuration>
                
                <executions>
                  <execution>
                    <phase>compile</phase>
                    <goals>
                      <goal>editResource</goal>
                    </goals>
                  </execution>
                </executions>
              </plugin>            
        </plugins>


5) 打包工程 mvn -Dmaven.test.skip=true package
分享到:
评论

相关推荐

    jenkins 离线安装maven插件集合jenkins-maven.zip

    6. **使用Maven插件**: 一旦配置好,你就可以在Jenkins中创建Maven项目的构建任务了。通过指定POM文件(Project Object Model),Jenkins会自动执行`mvn clean install`或其他自定义的Maven目标,执行构建、测试和...

    eclipse的maven插件

    1. **创建Maven项目**:通过“File” -&gt; “New” -&gt; “Project” -&gt; “Maven Project”菜单,可以快速创建符合Maven标准目录结构的新项目。用户可以选择不同的archetype(模板)来生成特定类型的项目,如Web应用、...

    eclipse安装maven插件需要包

    5. **测试Maven插件**: 创建一个新的Maven项目,如果Eclipse能够自动生成`pom.xml`文件并正常识别依赖,那么Maven插件就已成功安装和配置。 总结,离线安装Eclipse的Maven插件是一种在无网络或网络不稳定情况下的...

    Myeclipse maven插件下载

    - 创建Maven项目:在MyEclipse中,可以选择“New” -&gt; “Other” -&gt; “Maven Project”来创建一个新的Maven项目。按照向导设置项目坐标(GroupId, ArtifactId, Version)和项目类型。 - 配置POM.xml:在Maven项目...

    Myeclipse6.5的Maven插件

    1. **项目创建**:Maven插件允许用户直接在MyEclipse中创建基于Maven的项目,选择相应的 archetype,可以快速生成各种类型的项目模板,如Web应用、EJB项目等。 2. **依赖管理**:Maven的中央仓库包含了海量的开源库...

    自定义maven插件的实现

    1. 创建Maven Plugin项目: - 使用Maven的`maven-plugin-plugin`来生成基础骨架。在命令行中运行: ``` mvn archetype:generate -DgroupId=...

    eclipse安装的maven插件

    通过Maven插件,Eclipse用户可以直接在IDE内部创建、编译、测试、打包和部署Maven项目,极大地提高了开发效率。 安装Maven插件的过程通常分为以下几步: 1. **下载Maven**:首先,你需要从Apache官方网站...

    安装Jenkins的git和maven插件

    本文将详细讲解如何在Jenkins中安装Git和Maven插件,以便实现版本控制与构建管理。 首先,让我们了解Jenkins插件的作用。Jenkins通过插件扩展其功能,提供对各种工具和技术的支持。Git插件允许Jenkins与Git仓库进行...

    eclipse安装maven插件

    7. **创建或导入Maven项目**:现在你可以开始使用Maven插件了。可以通过“File” -&gt; “New” -&gt; “Maven Project”来创建一个新的Maven项目,或者通过“File” -&gt; “Import” -&gt; “Existing Maven Projects”导入已...

    替换myeclipse默认maven插件

    myeclipse自带有maven插件相难用,而且不能创建maven项目,需要独立安装,即可顺利创建maven项目。 1、删除默认的maven,在该目录下直接搜索maven,删除所有相关的jar和目录。 2、下载maven文件,从...

    maven插件压缩包

    在给定的“maven插件压缩包”中,虽然没有具体的插件代码,但我们可以根据通常的Maven插件应用场景进行讨论。 ** Maven插件系统** Maven插件是Maven生态系统的核心组成部分,它们定义了一系列可执行的目标(Goals...

    jenkins 必装maven插件

    1. **创建Maven项目**:在Jenkins中新建一个Maven项目,提供项目的POM.xml文件路径,Jenkins将自动解析项目信息。 2. **配置构建触发器**:根据需求设置构建触发策略,例如定时构建、代码仓库 webhook 等。 3. **...

    手动快速在myeclipse上安装maven插件

    5. **创建Maven项目**:安装完成后,现在可以在MyEclipse中创建Maven项目。选择"File" -&gt; "New" -&gt; "Other" -&gt; "Maven" -&gt; "Maven Project"。按照向导步骤,选择项目类型,然后MyEclipse会自动生成符合Maven标准目录...

    Myeclipse10安装maven插件

    ### MyEclipse10安装与配置Maven插件详尽指南 #### 一、Maven简介及重要性 Maven是一款强大的项目管理工具,主要用于Java项目的构建、依赖管理和项目信息管理。通过Maven,开发者可以方便地管理项目的依赖关系、...

    maven插件 免费

    3. **创建Maven项目**:选择File &gt; New &gt; Maven Project,根据项目需求选择合适的Maven Archetype来创建项目,自动生成标准的项目结构。 4. **编辑POM.xml**:在项目中,POM.xml是核心文件,包含了项目信息、依赖、...

    eclipse-maven3-plugin Maven插件离线安装包

    打开并输入:path= D:/Development/eclipse-JavaEE/eclipse/plugins/maven(请参照上面对应你的 maven 插件) 4. 重启 eclipse,OK,完成了,启动后你打开Window ---&gt; Preferences 会发现一个多了一个选项Maven...

Global site tag (gtag.js) - Google Analytics