When importing a java library class from jar, is this considered static linking? or dynamic?

18,735

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

Solution 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 that .* is bad because of the naming and class discovery conflicts that it might incur, nothing to do with class referencing.

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

Share:
18,735

Related videos on Youtube

Jim Ford
Author by

Jim Ford

I am a husband, father, coder, and bass player.

Updated on September 24, 2020

Comments

  • Jim Ford
    Jim Ford almost 4 years

    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?

    • tim_yates
      tim_yates over 13 years
      Neither, it's considered a dependency
    • peter.murray.rust
      peter.murray.rust over 13 years
      I think it can matter for some licences. I have been involved in a case where a library was LGPL and the caller therefore linked dynamically to avoid the viral licence - static linking would cause their code to be LGPL compliant
    • Jim Ford
      Jim Ford over 13 years
      so because java does it dynamically an LGPL licensed lib can be used in a commercial product without forcing the calling code to be LGPL?
    • Jim Ford
      Jim Ford over 13 years
      thanks for the comments guys, very helpful.
  • Ilya Saunkin
    Ilya Saunkin over 13 years
    Cool. I thought it was part of the question.
  • ILMTitan
    ILMTitan over 13 years
    Um, the import statements are not included in the compiled byte-code. Everything is referenced by its full name. The problem with importing package.* is the high potential for naming conflicts.
  • biziclop
    biziclop over 13 years
    And if you work for a company and this is part of your work, chances are that there is some company policy governing it as well.