Maven插件开发
2015-07-03 09:07
316 查看
首先使用命令创建Maven工程:
mvn archetype:generate -DgroupId=groupId -DartifactId=artifactId -DarchetypeArtifactId=maven-archetype-mojo
然后想在Eclipse下编辑工程,使用下面的命令把工程进行了转化:
mvn eclipse:eclipse
完成后新建class:
修改pom.xml:
mvn clean install
生成插件并安装到本地库
另外在记录一下:
添加单个jar到maven本地仓库的操作如下:
1.建立一个新的文件夹,将jar文件存放在该文件夹下。注意文件夹下最好只存放该文件。
2.在cmd窗口中执行以下命令: mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
例如:
mvn install:install-file -Dfile=xxx.jar -DgroupId=xxx -DartifactId=xxx -Dversion=1.0.0 -Dpackaging=jar
mvn archetype:generate -DgroupId=groupId -DartifactId=artifactId -DarchetypeArtifactId=maven-archetype-mojo
然后想在Eclipse下编辑工程,使用下面的命令把工程进行了转化:
mvn eclipse:eclipse
完成后新建class:
@Mojo(name="instrument", requiresDependencyResolution=ResolutionScope.COMPILE, defaultPhase=LifecyclePhase.VALIDATE) public class xxxMojo extends AbstractMojo { public void execute() throws MojoExecutionException { String nameOfRunningVM = ManagementFactory.getRuntimeMXBean().getName(); int p = nameOfRunningVM.indexOf('@'); String pid = nameOfRunningVM.substring(0, p); String jarFilePath = null; getLog().info("Dynamically loading xxx instrumentation..."); try { jarFilePath = xxx.class.getProtectionDomain().getCodeSource().getLocation() .toURI().getPath().toString(); jarFilePath = new File(jarFilePath).getCanonicalPath(); getLog().info("Found xxx instrumentation within " + jarFilePath); } catch (URISyntaxException e) { getLog().error("Unable to find xxx instrumentation jar"); throw new RuntimeException(e); } catch (IOException e) { getLog().error("Unable to find xxx instrumentation jar"); throw new RuntimeException(e); } try { VirtualMachine vm = VirtualMachine.attach(pid); vm.loadAgent(jarFilePath, System.getProperty("xxx.AgentArgs")); vm.detach(); } catch (Exception e) { getLog().error("Error encountered while loading the xxx agent", e); throw new RuntimeException(e); } } }
修改pom.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>groupId</groupId> <artifactId>artifactId</artifactId> <version>1.0.0</version> <packaging>maven-plugin</packaging> <name>xxx Agent Maven Plugin</name> <description>The xxx Agent provides run time performance monitoring for xxx applications</description> <url>http://www.xxx.com/</url> <licenses> <license> <name>The Apache Software License, Version 2.0</name> <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> <distribution>repo</distribution> </license> </licenses> <developers> <developer> <id>zach</id> <name>Zach Liu</name> <email></email> </developer> </developers> <!-- <scm> <connection>scm:git:git@github.com:xxx/android_agent.git</connection> <url>git@github.com:xxx/android_agent.git</url> </scm> --> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <profiles> <profile> <id>default-profile</id> <activation> <activeByDefault>true</activeByDefault> <file> <exists>${java.home}/../lib/tools.jar</exists> </file> </activation> <properties> <toolsjar>${java.home}/../lib/tools.jar</toolsjar> </properties> </profile> <profile> <id>mac-profile</id> <activation> <activeByDefault>false</activeByDefault> <file> <exists>${java.home}/../Classes/classes.jar</exists> </file> </activation> <properties> <toolsjar>${java.home}/../Classes/classes.jar</toolsjar> </properties> </profile> </profiles> <dependencies> <!-- our rewriter --> <dependency> <groupId>groupId</groupId> <artifactId>artifactId</artifactId> <version>1.0.0</version> </dependency> <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> <dependency> <groupId>sun.jdk</groupId> <artifactId>tools</artifactId> <version>xxx</version> <scope>system</scope> <systemPath>${toolsjar}</systemPath> </dependency> </dependencies> <build> <finalName>${project.artifactId}-${project.version}</finalName> <sourceDirectory>src</sourceDirectory> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-plugin-plugin</artifactId> <version>3.2</version> <configuration> <goalPrefix>agent</goalPrefix> <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound> </configuration> <executions> <execution> <id>mojo-descriptor</id> <goals> <goal>descriptor</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
mvn clean install
生成插件并安装到本地库
另外在记录一下:
添加单个jar到maven本地仓库的操作如下:
1.建立一个新的文件夹,将jar文件存放在该文件夹下。注意文件夹下最好只存放该文件。
2.在cmd窗口中执行以下命令: mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
例如:
mvn install:install-file -Dfile=xxx.jar -DgroupId=xxx -DartifactId=xxx -Dversion=1.0.0 -Dpackaging=jar
相关文章推荐
- C++结构变量数据对齐问题
- C++结构变量数据对齐问题 分类: C/C++ 2015-07-03 09:07 157人阅读 评论(0) 收藏
- cacti
- 用beamoff给VMware的Mac OS X 10.10.x加速
- 解析config.json
- 郑伯克段于鄢
- TStringList 常用操作
- Leetcode 121 Best Time to Buy and Sell Stock
- android 单选按钮 确定对话框
- 《Java课程实习》日志(周三)
- sizeof和strlen的区别
- 此生若能得幸福安稳,谁又愿颠沛流离
- sizeof和strlen的区别 分类: C/C++ 2015-07-03 09:05 169人阅读 评论(0) 收藏
- PHP面向对象编程之--多态:方法重载与重写
- 关于android .9.png图片,中文简称点九
- BI还是报表
- java总结(之五)-- 类与接口、多态与继承
- Linux安装JDK1.7
- iOS 字符串变成16进制 数字不变
- MySQLMigrationTool 出现jre的错误