从 jar 导入 java 库类时,这是否被视为静态链接?还是动态的?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4805577/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
When importing a java library class from jar, is this considered static linking? or dynamic?
提问by Jim Ford
say I have jcifs-1.3.14.jar in my lib folder, and I have a class that is importing from the library and uses the classes like:
假设我的 lib 文件夹中有 jcifs-1.3.14.jar,并且我有一个从库中导入的类并使用如下类:
import jcifs.smb.*;
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(domain,
user,
pass);
SmbFile file = new SmbFile(path, auth);
// do some operations with the file here
When using the library in this fashion is it considered to be: A) Static Linking OR B) Dynamic Linking OR C) something else?
当以这种方式使用库时,它被认为是:A) 静态链接或 B) 动态链接或 C) 其他东西?
采纳答案by thkala
If you are looking for information about applying various software licenses on Java programs, then searching Google for <license name> Java
usually results in a useful hit.
如果您正在寻找有关在 Java 程序上应用各种软件许可证的信息,那么在 Google 上搜索<license name> Java
通常会得到有用的结果。
E.g for LGPL Java
, thisis the first hit. In this particular case, the bottom line is:
例如,对于LGPL Java
,这是第一次命中。在这种特殊情况下,底线是:
Applications which link to LGPL libraries need not be released under the LGPL. Applications need only follow the requirements in section 6 of the LGPL: allow new versions of the library to be linked with the application; and allow reverse engineering to debug this.
链接到 LGPL 库的应用程序不需要在 LGPL 下发布。应用程序只需遵循 LGPL 第 6 节的要求:允许新版本的库与应用程序链接;并允许逆向工程对此进行调试。
I.e. as long as the library is provided in a separate JAR file that can be easily replaced, LGPL allows it.
即只要库是在一个单独的 JAR 文件中提供的,可以很容易地替换,LGPL 允许它。
PS: I Am Not A Lawyer! If in doubt, consult one. As a matter of fact, depending on where you live, it might make sense to consult one regardless if you are in doubt or not.
PS:我不是律师!如有疑问,请咨询一位。事实上,根据你住的地方,不管你是否有疑问,咨询一个人可能是有意义的。
回答by Elijah Saounkine
Static vs dynamic as in C++ doesn't exist in Java. All class get loaded into JVM as they are referenced, so you'd want to think that all imports (this includes reflections) in Java are dynamic.
Java 中不存在 C++ 中的静态与动态。所有类都在被引用时加载到 JVM 中,因此您可能会认为 Java 中的所有导入(包括反射)都是动态的。
And yes, that .* is bad exactly because it references all the classes in that package.
是的,那个 .* 很糟糕,因为它引用了该包中的所有类。
回答by FolksLord
Well, you don't compile the code from library into your java classes. Your compiled classes refere the classes from other library by name. When need, the class is loaded by class loader. It's more similar to dynamic linking.
好吧,您不会将库中的代码编译到您的 Java 类中。您编译的类通过名称引用来自其他库的类。需要时,类由类加载器加载。它更类似于动态链接。
From licencing point of view - f.g. LGPL licence, it should be considered as dynamic linking. I've never heard of any law proceeding in that case (though I've searched for it), but it is high propable, I'm looking forward to it, because many developers are a bit anxious about it.
从许可的角度来看——fg LGPL 许可,它应该被视为动态链接。我从未听说过在这种情况下有任何法律程序(尽管我已经搜索过),但它的可能性很高,我很期待,因为许多开发人员对此有点担心。