2

I have the following questions:

  1. In general: what is compile- and run-time dependencies
  2. How the javac compiler does compile-time dependency resolution
  3. How the VM does runtime-dependency resolution

I've skimmed the JLS and JVMS for "dependency" but haven't come up with anything.

An SO User
  • 24,612
  • 35
  • 133
  • 221
johnrl
  • 583
  • 6
  • 17

2 Answers2

2

In general: what is compile- and run-time dependencies

  • Compile-time dependency: You need the dependency in your CLASSPATH to compile your artifact. They are produced because you have some kind of "reference" to the dependency hardcoded in your code, such as calling new for some class, extending or implementing something (either directly or indirectly), or a method call using the direct reference.method() notation.

  • Run-time dependency: You need the dependency in your CLASSPATH to run your artifact. They are produced because you execute code that accesses the dependency (either in a hardcoded way or via reflection or whatever).

Taken from: Compile time vs Run time Dependency - Java however, a much detailed reference is available on Jenkov's website

How the javac compiler does compile-time dependency resolution

It looks at your classpath and sourcepath to find the necessary dependencies.

How the VM does runtime-dependency resolution

The JVM isn't exactly concerned with dependency resolution, AFAIK. What the JVM does is to load classes from the classpath when they are needed. For example, when your program (say class A) hits the first time:

// in class A
F x = new F(42);

the class F will be loaded.

If the class is not found, you get a ClassNotFoundException. If you changed the F class between compilation of A and execution, and dropped, for example, the F(int) constructor, then you get several different ugly exceptions.

Community
  • 1
  • 1
An SO User
  • 24,612
  • 35
  • 133
  • 221
0

"Dependency" is higher level of abstraction than the JVM is concerned with. There are many dependency management systems out there, like Maven and Gradle, but each of these runs on top of the JVM, not as part of it itself.

What you'll find in the Java platform documentation is "linking"; i.e., how the JVM can use the name of a Class or Interface to locate the byte code necessary to load additional pieces of your program. Java does this via a mechanism called the classpath. The classpath can be configured via environment variables, your build system, or at the command line as you run a program.

Peter Bratton
  • 6,302
  • 6
  • 39
  • 61