Java -classpath option

将 选项与 、 一起使用是否会添加或替换 env 变量的内容?-classpathjavaCLASSPATH


答案 1

使用类路径变量,它将覆盖环境变量的类路径,但仅适用于该会话。如果重新启动应用程序,则需要再次设置类路径变量。


答案 2

是的。引自手册页:java(1)

   -classpath classpath
   -cp classpath
          Specifies a list of directories, JAR archives, and ZIP archives to search  for  class  files.   Class
          path  entries  are separated by colons (:). Specifying -classpath or -cp overrides any setting of the
          CLASSPATH environment variable.

          If -classpath and -cp are not used and CLASSPATH is not set, the user class path consists of the cur-
          rent directory (.).

推荐