同一个类在多个jar中 [英] Same class is in multiple jar

查看:144
本文介绍了同一个类在多个jar中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个包含完全相同类的罐子。

I have several jars containing the exact same class.

比如说,A.jar和B.jar有相同的Hello.class类。如果我运行以下内容会发生什么:

Lets say for example, A.jar and B.jar have the same class Hello.class. What will happen if I run the following:

java -classpath A.jar; B.jar com.testing.testcode

java -classpath A.jar;B.jar com.testing.testcode

我的问题是它是否会运行?从我的理解类加载器将扫描类路径,它将返回它首先找到的任何Hello.class。

My question is whether it will run or not? As from my understanding class loader will scan the classpath and it will return whatever Hello.class it finds first.

我知道如果我使用OSGi加载,我可以避免这个问题一个特定的类。

I know I can avoid this problem if I use OSGi for loading a particular class.

但我的问题是 - 这是否会运行?或者java -classpath A.jar; B.jar com.testing.testcode将分解为同一个类的两个版本。

But what my question is – whether this will run or not? Or the java -classpath A.jar;B.jar com.testing.testcode will break down for having two version of the same class.

推荐答案

这将有效,并且将使用类路径中的第一个Hello类,因此在这种情况下,来自A.jar的那个

This will work and the first Hello class in the classpath will be used, so in this case, the one from the A.jar

这篇关于同一个类在多个jar中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆