精华内容
下载资源
问答
  • 解决jar引用不同版本冲突问题

    千次阅读 2019-12-04 14:52:25
    对于引用Jar版本冲突是很常见的问题,其中最坑的就是jar内引用不同版本jar,导致版本冲突,转发的帖子能够很好的解决这一类问题。 Before version 2.0, Elasticsearch was provided as a JAR with some (but ...

    转自:https://www.elastic.co/cn/blog/to-shade-or-not-to-shade

    对于引用Jar包版本冲突是很常见的问题,其中最坑的就是jar内引用不同的版本jar,导致版本冲突,转发的帖子能够很好的解决这一类问题。

    Before version 2.0, Elasticsearch was provided as a JAR with some (but not all) common dependencies shaded and packaged within the same artifact. This helped Java users who embed Elasticsearch in their own applications to avoid version conflicts of modules like Guava, Joda, Jackson, etc. Of course, there was still a list of other unshaded dependencies like Lucene that could still cause conflicts.

    Unfortunately, shading is a complex and error prone process which solved problems for some people while creating problems for others. Shading makes it very difficult for developers and plugin authors to write and debug code properly because packages are renamed during the build. Finally, we used to test Elasticsearch unshaded then ship the shaded jar, and we don’t like to ship anything that we aren’t testing.

    We have decided to ship Elasticsearch without shading from 2.0 onwards.

    Dealing with version conflicts

    If you want to use Elasticsearch in your Java application, you may have to deal with version conflicts with third party dependencies like Guava and Joda.  For instance, perhaps Elasticsearch uses Joda 2.8, while your code uses Joda 2.1.  You have two choices:

    The simplest solution is to upgrade. Newer module versions are likely to have fixed old bugs. The further behind you fall, the harder it will be to upgrade later. Of course, it is possible that you are using a third party dependency that in turn depends on an outdated version of a package, which prevents you from upgrading.  

    The second option is to relocate the troublesome dependencies and to shade them either with your own application or with Elasticsearch and any plugins needed by the Elasticsearch client.

    How to shade Elasticsearch

    To help you achieve this, we have put together an example application which allows you to run:

    • the Elasticsearch transport client
    • with the Shield security plugin
    • and a conflicting version of Joda.

    Your project’s pom.xml probably looks something like this:

    <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>

    The problem with the above is the Joda dependency: your project requires Joda 2.1, but Elasticsearch 2.0.0-beta2 requires Joda 2.8.

    Shading Elasticsearch

    To resolve this situation, we create a new maven project that shades Elasticsearch and Shield.  The pom.xml should look like this:

    <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>

    Shade and relocate conflicting packages

    Now shade and relocate all the packages which conflict with your own application by adding something like the below to the pom.xml.  This example adds Joda 2.8:

    <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>

    Running mvn clean install will create a shaded version of Elasticsearch, Shield, and Joda 2.8 which you can depend on in your application.

    Embed this jar within your application

    In your project, you can now depend on:

    <!-- 
     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>

    You can build and use the Elasticsearch TransportClient as before:

    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)));

    To use your own version of Joda, just import org.joda.time.DateTime. You can even access the shaded version of Joda by importing my.elasticsearch.joda.time.DateTime, although we don’t recommend doing so. Here’s an example showing how both versions can be accessed within the same JVM:

    // import org.joda.time.DateTime;
    // import my.elasticsearch.joda.time.DateTime;
    CodeSource codeSource = new org.joda.time.DateTime().getClass().getProtectionDomain().getCodeSource();
    System.out.println("unshaded = " + codeSource);
    codeSource = new my.elasticsearch.joda.time.DateTime().getClass().getProtectionDomain().getCodeSource();
    System.out.println("shaded = " + codeSource);

    It will print:

    unshaded = (file:/path/to/joda-time-2.1.jar <no signer certificates>)
    shaded = (file:/path/to/es-shaded-1.0-SNAPSHOT.jar <no signer certificates>)

    Take a look at this demo project which shows a full running example of the above.

    Future developments

    Dealing with version conflicts is a perennial problem, but in the future we would like to make it easier than it is today. The simplest way to reduce conflicts between third party dependencies is to reduce the number of dependencies that Elasticsearch has.  We will never be able to remove all dependencies, but we’re making a start by removing Guava in favour of native Java 8 code. We will also be investigating replacing Joda with Java.time (also in Java 8), and possibly even creating a thin Java client for Elasticsearch with minimal dependencies.

     

    Of course, these changes are not small.  Whatever we end up deciding is the right path to follow in the long term, it will take time for us to reach the destination.  In the meantime, we wanted to provide a relatively simple solution for today’s problems.

    展开全文
  • 测试环境和正式环境引用不同版本jar包,当引用某一个版本时会去私服取最新版本的代码比如  pay-provider-client-1.0.0-20150721.063558-1.jar  下载到本地仓库后会复制一份重命名为 pay-provider-client -1.0.0-...

     pom文件中定义: 

    <!-- 测试环境 -->
    <profile>
    	<id>dev</id>
    	<activation>
    		<activeByDefault>true</activeByDefault>
    	</activation>
    	<properties>
    		<profiles.active>dev</profiles.active>
    		<pay.dubbo.version>1.0.0-SNAPSHOT</pay.dubbo.version>
    	</properties>
    	<dependencies>
    		<!-- pay_provider -->
    		<dependency>
    			<groupId>com.anzhi</groupId>
    			<artifactId>pay-provider-client</artifactId>
    			<version>${pay.dubbo.version}</version>
    		</dependency>
    	</dependencies>
    </profile>
    <!-- 生产环境 -->
    <profile>
    	<id>site</id>
    	<activation>
    		<activeByDefault>false</activeByDefault>
    	</activation>
    	<properties>
    		<profiles.active>site</profiles.active>
    		<pay.dubbo.version>1.1.1-RELEASE</pay.dubbo.version>
    	</properties>
    	<dependencies>
    		<!-- pay_provider -->
    		<dependency>
    			<groupId>com.anzhi</groupId>
    			<artifactId>pay-provider-client</artifactId>
    			<version>${pay.dubbo.version}</version>
    		</dependency>
    </profile>

    测试环境和正式环境引用不同版本的jar包,当引用某一个版本时会去私服取最新版本的代码比如  pay-provider-client-1.0.0-20150721.063558-1.jar  下载到本地仓库后会复制一份重命名为pay-provider-client-1.0.0-snapshot.jar

     

    同义pay-provider项目中打包也会根据pom文件中的定义打包成jar包 根据版本上传到指定版本的私服中

    扩展知识:  freemarker-2.3.8.jar.sha1是freemarker-2.3.8.jar的校验文件;freemarker-2.3.8.pom是管理描述文件;freemarker-2.3.8.pom.sha1是freemarker-2.3.8.pom的校验文件。

     

     

     

    展开全文
  • @解决不同版本jar包引入问题,修改jar包包名 jarjar1.1 最近用到改jar包包名,找了半天没有免费资源,发一个 https://pan.baidu.com/s/170yf5eHcY-SboBAF24P1Gg 提取码ha7d 欢迎使用Markdown编辑器 你好! 这是...

    @解决不同版本jar包引入问题,修改jar包包名
    jarjar1.1 最近用到改jar包包名,找了半天没有免费资源,发一个
    https://pan.baidu.com/s/170yf5eHcY-SboBAF24P1Gg 提取码ha7d

    展开全文
  • 压缩包里面有myself工程。里面只有一个类。可以自己创建两个版本的myself的jar包,然后测试osgi解决jar包冲突。
  • 文章目录1....1.我们在导入项目的过程中,可能会出现,因为找不到某个jar包,导致我们的项目报错,编译不通过的情况; 针对这种问题,我们如何去解决呢?都有哪些可以参考的方案 1.2.图示描述 2.参考...

    1.问题描述

    1.1.文字描述

    1.我们在导入项目的过程中,可能会出现,因为找不到某个jar包,导致我们的项目报错,编译不通过的情况;
      针对这种问题,我们如何去解决呢?都有哪些可以参考的方案
    

    1.2.图示描述

    2.参考解决方案

    2.1.确认仓库中确实有该版本

    2.2.删除 *lastUpdated文件,由于有这个文件,不会在下载该版本

    进入自己的仓库目录

    MacBook-Pro:repository gaoxinfu$ pwd
    /Users/gaoxinfu/.m2/repository
    MacBook-Pro:repository gaoxinfu$ 
    

    执行下面命令

    find . -name "*lastUpdated" | xargs rm -fr
    

    2.3.使用mvn compile编译一下看看具体错误信息

    在这里插入图片描述

    1.有可能会发现,具体的某个地址打不开,导致无法编译找到jar
      或者有可能私服仓库打不开等等原因
    
    展开全文
  • 1. 应用场景有时候我们需要在一个 Project 中运行多个不同版本jar 包,以应对不同集群的版本或其它的问题。如果这个时候选择在同一个项目中实现这样的功能,那么通常只能选择更低版本的 jar 包,因为它们通常是向...
  •  同一个JVM进程中,往往会部署不同的java应用,不同业务开发人员会采用同一个组件包的不同版本,此时部署在同一个JVM中会出现常见的JAR冲突问题,导致涉及的多个应用无法正常使用。那么,怎样才能实现不同应用正常...
  • 通过 mvn dependency:tree 查看 多个包引入的依赖; 在eclipse中直接选中包,右->maven exclude maven artifact 即可
  • c#引用jar

    千次阅读 2019-05-08 17:50:45
    c#引用jar
  • 这样一个项目工程,其中查看edaily-service与edaily-web引用jar版本有不一致的情况。 以spring 的版本为例:web为4.3.29 而service存在4.0.9的版本: 那么在maven打成war的时候,使用的是4.0.9的jar还是4.3.29的...
  • 项目中引用jar版本冲突

    千次阅读 2018-08-12 20:39:36
    项目中引用jar版本冲突 留高版本 去除低版本 &lt;!-- jasperreport --&gt; &lt;dependency&gt; &lt;groupId&gt;net.sf.jasperreports&lt;/groupId&gt; &lt;artifactId&...
  • weblogic 10 及以后版本引用 weblogic.jar

    万次阅读 2015-01-19 20:14:17
    weblogic10 及以后的版本,不能直接使用server/lib 目录下的 weblogic.jar 了,需要通过执行一个命令生成手动生成 wlfullclient.jar,用来替代老版本中的 weblogic.jar。  具体命令如下(Windows 系统,我的 ...
  • 查看jar引用类库版本

    千次阅读 2018-09-26 11:59:39
    使用命令: gradlew -q app:dependencies  
  • 于是我随意打开了项目中的一个类,点进了这个类中引用的slf4j的jar包里,发现jar包中的META-INF文件夹中有一个MANIFEST.MF文件:这里写明了jar包被编译的版本,因为jar包包含的都是.class文件,所以已经提前编译过了...
  • import java.util.Map; import org.apache.struts2.interceptor.ApplicationAware; import org.apache.struts2.interceptor.RequestAware;... ``` 这样就好了,如果每个.jar包文件里的类都这么写就没有版本问题了,多好.
  • java 打包成war里,能否不将引用jar包打入,让它引用外部的jar
  • java打jar包,引用其他.jar文件

    千次阅读 2017-10-11 19:22:27
    大家都知道一个java应用项目可以打包成一个jar,当然你必须指定一个拥有main函数的main class作为你这个jar包的程序入口。具体的方法是修改jar包内目录META-INF下的MANIFEST.MF文件。比如有个叫做test.jarjar包,...
  • 2. 删除libs文件夹下的android-support-v4.jar; 3. 右击项目, 选择Properties-->Android-->点击Library选项框中的Add...按钮-->添加需要的Library-->然后会发现自动生成了Android Private Libraries, 观察androi
  • idea使用maven构建后台项目到仓库,前台项目引用后台项目jar包,前台项目引用后台项目的方法,怎么查看后台方法的注释?
  • eclipse项目编译版本是1.6,但是引用jar包的编译版本是1.7 ,报错信息如下: Description Resource Path Location Type Incompatible .class files version in required binaries. Project '28[nanjing
  • maven子项目无法引用父项目jar

    千次阅读 2019-08-19 10:21:29
    这是我的项目结构 ...3.springboot 本身依赖加入包需要从父pom中移除,否者子项目直接引用父pom里面springboot相关jar包,从而找不到里面的版本号 问题解决 把这个jar从父pom中移除,问题解决 ...
  • maven项目引用不了jar包的问题

    千次阅读 2018-05-10 21:00:46
    但是不能引用,经查询控制台输出信息,有惊人的发现,其中提示我一个警告,在多少行多少列,因为是刚刚涉猎maven 许多地方都是来自网上的摘抄,不清楚具体的含义,因此直接删除掉警告的内容,再重新引用jar包时,...
  • Android Studio:如何处理不同引用库(module)里jar的重复引用 将Module对jar的依赖关系从compile改为provided,这样jar文件将只能提供给对应的module使用,而外部无法通过编译获取。 方法...
  • JAR引用其它JAR包的classpath问题

    千次阅读 2015-08-11 11:35:26
    不过如果工程引用到了其它jar,虽然用ide工具打包时可以看到引用JAR已经加入到了自己的JAR中,但运行时却会提示ClassNotFoundException。 此时需要修改ide工具自动生成的hello.jar中的MANIFEST.MF,通过MANIFEST....
  • 同一个jar不同版本冲突解决方法

    万次阅读 2016-11-21 17:15:12
    一个项目里面同一个jar包一般不能有两个版本的 不然可能会出现jar包冲突的情况常见报错有这三个: 1、java.lang.ClassNotFoundException(找不到类) 2、java.lang.NoSuchMethodError(找不到具体方法) 3、java.lang...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 242,544
精华内容 97,017
关键字:

引用了不同版本的jar