当前位置:   article > 正文

elasticsearch引用jar包与其他jar冲突解决办法_org.elasticsearch.xpack.sql.proto.sqlqueryresponse

org.elasticsearch.xpack.sql.proto.sqlqueryresponse 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项目进行如下配置

<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 including
the 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)












声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/68454?site
推荐阅读
相关标签
  

闽ICP备14008679号