there is a AAA
class with a static member variable custCount
, which is an atomic class.
is then used in another class.
in theory, when this member variable is called, the AAA
class is loaded and then initialized.
does this when local debug in Idea.
but after the jar package, through the java-jar xxx
runtime, An exception will be reported: java.lang.ExceptionInInitializerError
.
what a weird mistake.
:
:
, edgeCount
custCount
:private static final String STAT_FILE_NAME1 = AAA.class.getClassLoader().getResource("").getPath() + "stat/stat.txt";
AAA.class.getClassLoader().getResource("")
jarnull. NullPointerException. , ExceptionInInitializerError
""NullPointer.
:
-
AAA.class.getClassLoader().getResource("")
. -
AAA.class.getResource("")
(jar).
!!.
Summary:
my goal is to get the path where the jar package is located . This getResource ()
mode does not meet my needs in jar package running mode.
previous experiments: new File ("")
can get the of the path where the jar package is located. Don"t struggle with it. Let"s use this method for the time being ~