Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$CLASSPATH and -cp with Java

  • In this post, using -jar option ignores all the -cp and $CLASSPATH.
  • In this post, using -cp option also ignores the $CLASSPATH.

Is there any good reason for them?

like image 715
prosseek Avatar asked Dec 02 '22 04:12

prosseek


1 Answers

It's to avoid clashes in the classpath whenever you distribute your application to run on different environments. In most of the cases you'd like your application to be independent from the platform specific configuration. If the $CLASSPATH contains references to classes with (either unawarely or awarely) the same package and classname, it would get precedence in classloading before the classes which you included in your application's classpath. This may lead to unexpected application behaviour or potential security holes.

like image 146
BalusC Avatar answered Dec 06 '22 11:12

BalusC