ras oscar wrote:when I was doing C++ many years ago, it seemed that the Microsoft IDE was invoking bat files in the background to build the application. I remember I got compiler errors and link errors. Does java not have an internal linker to resolve external dependencies?
One of the biggest differences between C/C++ and Java is how they form programs.
In C (or C++), you compile your source files, link in external libraries, and get a (more or less) stand-alone executable file that can be directly loaded and run by the OS loader.
In Java, what's executed is the Java Virtual Machine (JVM), which is supplied with classes to execute. The classes may be loose (in a directory tree) and/or in Java Archive (JAR) files, which are actually just ZIP files full of classes plus one or more files of interest to Java (the META-INF directory). Incidentally, a JAR inside another JAR is not normally accessible to the Java class loader. Although some specialized run environments have exceptions to that rule.
While some JARs contain complete executable applications, Java often requires additional class resources. The totality of all the classes is the core classes in the JVM (stuff like java.lang.Object and java.lang.String) plus what's in your classpath
. The classpath is like the PATH for executables except that the OS program loader knows nothing about it - it's used ONLY by the JVM to locate and load classes and class resources. The classpath locates the JVM internal classes plus additionally-specified class directory trees and/or JARs containing class resources. Actually, it's a concatenation of paths in most cases and in some systems there may be more than one classpath. For example webapp servers have a distinct classpath for each webapp, plus one or more for the internal processes of the webapp server (which is usually a Java Application).
You also need a classpath when compiling Java code, since unlike C (I'll assume this includes C++ for brevity going forward), there are no separate header and code files in Java. The "header" comes from referencing the compiled class itself. Note that at this level a Java Interface is itself a class, just in case you thought it was a header file.
So you have to have access to both your own source code and the compiled code of external class resources that your code needs. These are provided to the javac compiler via the classpath specified when you run javac (or when a tool such as Maven or Ant runs javac).
One of the reasons why Maven became popular was that instead of having to assemble all your external class references manually, you can indicate what classes you need in your Maven project's POM file. Maven will then go to the Internet and pull them from public repositories and cache them in a per-user local directory - which means that the slower network access is only done once. This cache is then available to all Maven compiles done for that user account, eliminating duplication of common resources and, incidentally ensuring that Maven-managed code is "write-once/compile
anywhere". Ant doesn't normally do this, but the Ant Ivy extension does.