System.getProperty(“java.class.path”) does not show “WEB-INF/lib” and the including jars

后端 未结 4 1227
迷失自我
迷失自我 2021-01-07 06:45
String CompilePath = \"abc.java\";
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
String classpath = System.getProperty(\"java.class.path\");
System.s         


        
4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-07 07:17

    You cannot depend on java.class.path to be set to anything in particular.

    Java establishes this variable when it launches the entire JVM containing your servlet container. As it creates many different class loaders for many different other purposes, it does not change it. It cannot. There is only one value of java.class.path for the entire process, but there can be many different webapps, and indeed many different class loaders inside each webapp.

    You will need your own explicit configuration mechanism to communicate the class path for this sort of compilation stuff, and to use getRealPath to construct the pathnames.

提交回复
热议问题