Say I have two classes (Bob and Tom) that Bob uses Tom, but Tom does not require Bob. Both of these files are in the same directory structure.
public class Bob {
public static void main(String[] args) {
System.out.println(Tom.MESSAGE);
}
}
public class Tom {
public static String MESSAGE = "Hello World";
}
If I try to compile Bob in a typical way, I can force him to implicitly compile Tom.java, since he is recognized as a dependency Bob.java. This works great.
But now say that I want to put Tom in a JAR file. Therefore, I build Tom.javaand put the results in a JAR file: libTom.jar. Now I am compiling with a classpath pointing to libTom.jar. Unfortunately, the compiler sees the file Tom.javaand forces it to compile, rather than using the class in libTom.jar. Is there a way to force the compiler to skip implicit building Tom.javaif the class is found in the classpath?
I understand that this example is pretty far-fetched. Be sure that there is a more complex, less far-fetched use case that surrounds this problem. Thank.
source
share