用maven2重写zookeeper客户端测试程序
来源:互联网 发布:中信银行淘宝卡 编辑:程序博客网 时间:2024/06/06 16:34
之前的zk_client.java用一种很取巧的办法来编译和运行,把jar包解压放到当前目录下。这种办法不太好,也不美观。
现在使用maven2重构整个代码。
1.首先运行create_mvn_project.sh com.luoyan.zookeepertest zookeepertest,本质上是运行以下的命令:
mvn archetype:generate \
-DarchetypeGroupId=org.apache.maven.archetypes \
-DgroupId=com.luoyan.zookeepertest \
-DartifactId=zookeepertest
该命令会自动生成pom.xml和src下的代码。
2.然后把原来的zk_client.java拷贝到src/main/java/com/luoyan/zookeepertest
3.在pom.xml中加上
<build>
<plugins>
<!–
Bind the maven-assembly-plugin to the package phase
this will create a jar file without the storm dependencies
suitable for deployment to a cluster.
–>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass></mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
4.在zk_client.java中加入package com.luoyan.zookeepertest;
5.添加依赖关系,主要是依赖zookeeper 3.4.5
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.5</version>
</dependency>
如果直接运行mvn package,会报错
The following artifacts could not be resolved: javax.jms:jms:jar:1.1, com.sun.jdmk:jmxtools:jar:1.2.1, com.sun.jmx:jmxri:jar:1.2.1: Failure to find javax.jms:jms:jar:1.1 in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]
所以要在zookeeper的依赖关系中再加上exclusion
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.5</version>
<exclusions>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
</exclusions>
</dependency>
6.运行mvn package生成 jar包
7.java -cp target/zookeepertest-1.0-SNAPSHOT-jar-with-dependencies.jar com.luoyan.zookeepertest.zk_client
就可以执行了。
- 用maven2重写zookeeper客户端测试程序
- 客户端工具测试 ZooKeeper
- Zookeeper和zkpython 客户端测试
- 第一个ZooKeeper客户端程序
- 客户端测试程序
- tuxedo客户端测试程序
- java客户端测试连接zookeeper服务器
- Zookeeper学习笔记:客户端程序分析一
- zookeeper-客户端
- Zookeeper客户端
- zookeeper客户端
- Zookeeper客户端
- Zookeeper客户端
- 测试使用zookeeper的c客户端的情况
- zookeeper客户端API编程CuratorFramework测试场景1
- Maven2.0构建,编译,测试
- Silverlight网页客户端测试服务器程序 服务器测试程序
- ZSChatServer线程设计模型---客户端测试程序
- maven使用初步
- 记录:动态日历生成
- kafka使用初步
- JAVA设计模式——装饰设计模式
- SQL Server之SQLEXPRESS和MSSQLSERVER两个服务的问题
- 用maven2重写zookeeper客户端测试程序
- 疯狂猜歌实现(1)—— 实现顶部布局
- 深入理解HTTP协议
- 新手如何做好微信营销
- 二维数组中的查找
- 外排序(磁盘排序)之多路归并排序的简单实现(转)
- Android之Handler用法总结
- Linux下Android内核源码下载
- Vector 的拷贝构造函数