elasticsearch引用jar包与其他jar冲突解决办法
来源:互联网 发布:linux修改ip 编辑:程序博客网 时间:2024/06/10 08:23
问题提出:
官网blog:https://www.elastic.co/blog/to-shade-or-not-to-shade
比如你的项目中引用的Joda 2.1,而elasticsearch 2.2.0引用的Joda 2.8,则在使用elasticsearch的时候以为会先找到Joda 2.1,导致elasticsearch用不起来,所以怎么解决呢
1.新建一个maven项目进行如下配置
<properties><elasticsearch.version>2.0.0-beta2</elasticsearch.version></properties><dependencies><dependency> <groupId>org.elasticsearch</groupId> <artifactId>elasticsearch</artifactId> <version>${elasticsearch.version}</version></dependency><dependency> <groupId>org.elasticsearch.plugin</groupId> <artifactId>shield</artifactId> <version>${elasticsearch.version}</version></dependency><dependency> <groupId>joda-time</groupId> <artifactId>joda-time</artifactId> <version>2.1</version></dependency></dependencies>
2.隐藏elasticsearch
<groupId>my.elasticsearch.test</groupId><artifactId>es-shaded</artifactId><version>1.0-SNAPSHOT</version><properties><elasticsearch.version>2.0.0-beta2</elasticsearch.version></properties><dependencies><dependency> <groupId>org.elasticsearch</groupId> <artifactId>elasticsearch</artifactId> <version>${elasticsearch.version}</version></dependency><dependency> <groupId>org.elasticsearch.plugin</groupId> <artifactId>shield</artifactId> <version>${elasticsearch.version}</version></dependency></dependencies><repositories><repository> <id>elasticsearch-releases</id> http://maven.elasticsearch.org/releases <releases> <enabled>true</enabled> <updatePolicy>daily</updatePolicy> </releases> <snapshots> <enabled>false</enabled> </snapshots></repository></repositories>
3.将elasticsearch中冲突的jar包
<build><plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>2.4.1</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <relocations> <relocation> <pattern>org.joda</pattern> <shadedPattern>my.elasticsearch.joda</shadedPattern> </relocation> </relocations> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer" /> </transformers> </configuration> </execution> </executions> </plugin></plugins></build>
4.你的项目中引用
<!--This artifact contains all elasticsearch libs includingthe shaded version of Joda and Shield --><dependency><groupId>my.elasticsearch.test</groupId><artifactId>es-shaded</artifactId><version>1.0-SNAPSHOT</version></dependency> <!-- You still use your own Joda version --><dependency><groupId>joda-time</groupId><artifactId>joda-time</artifactId><version>2.1</version></dependency>
5.使用 elasticsearch
TransportClient client = TransportClient.builder() .settings(Settings.builder() .put("path.home", ".") .put("shield.user", "username:password") .put("plugin.types", "org.elasticsearch.shield.ShieldPlugin") ) .build();client.addTransportAddress(new InetSocketTransportAddress(new InetSocketAddress("localhost", 9300)));
6说明
你可以使用org.joda.time.DateTime(2.1版本的),也可以使用my.elasticsearch.joda.time.DateTime(2.8版本的,不推荐用这个,而是直接用org.joda.time.DateTime)
0 0
- elasticsearch引用jar包与其他jar冲突解决办法
- es与其他服务(hbase,spark,hive)jar包冲突时如何定位冲突包
- jar 包冲突解决办法
- ElasticSearch JavaAPI jar包冲突
- Hbase与Elasticsearch的jar包冲突解决办法
- jquery与其他包冲突的解决办法
- Maven jar包冲突解决办法
- maven jar包冲突解决办法
- elasticsearch的jar包冲突解决笔记
- Hbase、elasticsearch整合中jar包冲突
- jquery与其他js包冲突时的解决办法
- android资源打jar包与其他解决方案
- android资源打jar包与其他解决方案
- android资源打jar包与其他解决方案
- Groovy引用Jar包冲突问题
- jboss 第三方jar包冲突解决办法
- SSH整合中的jar包冲突解决办法
- webshere下jar包冲突解决办法
- 分享一个解决旋转反方向的文档页面的办法
- 关于 hibernate import file not found: /import.sql 问题的解决
- 进程与线程
- 增强式for循环
- PAT-1013
- elasticsearch引用jar包与其他jar冲突解决办法
- [英]一步步实现Gradle插件
- Java中的深拷贝(深复制)和浅拷贝(浅复制)
- Git 安装配置和一些简单指令使用
- 【CSS】textarea标签中resize属性的设置
- Process Start打开excel文档显示显示因为文件格式或文件扩展名无效
- ubuntu下安装comsol
- Java并发编程系列之一:并发机制的底层原理
- 在Ubuntu上为Shutter添加快捷键