When importing a java library class from jar, is t

2019-04-18 04:19发布

问题:

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:

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?

回答1:

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.

E.g for LGPL Java, this is the first hit. In this particular case, the bottom line is:

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.

I.e. as long as the library is provided in a separate JAR file that can be easily replaced, LGPL allows it.

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.



回答2:

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.

And yes, that .* is bad exactly because it references all the classes in that package.



回答3:

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.

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.