elasticsearch引用jar包与其他jar冲突解决办法

问题提出:

官网bloghttps://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项目进行如下配置


2.0.0-beta2



    org.elasticsearch
    elasticsearch
    ${elasticsearch.version}


    org.elasticsearch.plugin
    shield
    ${elasticsearch.version}


    joda-time
    joda-time
    2.1


2.隐藏elasticsearch

my.elasticsearch.test
es-shaded
1.0-SNAPSHOT

2.0.0-beta2



    org.elasticsearch
    elasticsearch
    ${elasticsearch.version}


    org.elasticsearch.plugin
    shield
    ${elasticsearch.version}




    elasticsearch-releases
    http://maven.elasticsearch.org/releases
    
        true
        daily
    
    
        false
    


3.将elasticsearch中冲突的jar包 



    
        org.apache.maven.plugins
        maven-shade-plugin
        2.4.1
        
            
                package
                
                    shade
                
                
                    
                        
                            org.joda
                            my.elasticsearch.joda
                        
                    
                    
                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer" />
                    
                
            
        
    

4.你的项目中引用



my.elasticsearch.test
es-shaded
1.0-SNAPSHOT

        

joda-time
joda-time
2.1

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)












你可能感兴趣的:(云计算)