Javac vs Java within -classpath option

送分小仙女□ 提交于 2019-12-03 06:03:13

One is the classpath used for compiling. The other is the classpath used for running. And they do not have to be the same thing. The set of classes needed for the compilation processes are all those referred to by every class being compiled. Whereas your runtime JAR could be invoking a standalone class with an empty main method and no dependencies.

Just remember that at runtime class dependencies are resolved dynamically, aka a class is only loaded when it is needed (this is a generalization, boot and system classes are always loaded).

This document contains answers for your questions

http://docs.oracle.com/javase/1.4.2/docs/tooldocs/windows/javac.html

using -classpath every time is a very time consuming work. Instead, use environment variables (if you are dealing with a package such as Java Mail)

classpath is used for compiling. Javac is the Java Compiler, where it converts your code into byte code.

When it comes to java it is used to run your Java source file/jar.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!