public class PropHolder {
public static Properties prop;
static {
//code for loading properties from file
}
}
// Referencing the class somewhere else:
Properties prop = PropHolder.prop;
class PropHolder
是我自己的一个类。该类驻留在主类的同一个 JAR 文件中。所以这不应该是因为类路径中缺少任何 JAR。
当我通过 jar tf myjarfile
查看 JAR 文件时,我可以看到 PropHolder.class
列在那里。
顺便说一句:代码在我的本地机器上运行良好。但是当我用一些脚本将它部署到 Linux 服务器上时无法工作。所以我认为这不是代码的问题。但出于某种原因。部署过程很难跟踪。
可能是什么问题呢?
原文由 Leon 发布,翻译遵循 CC BY-SA 4.0 许可协议
我最好的选择是这里有一个问题:
似乎发生了一些未捕获的异常并传播到尝试加载该类的实际 ClassLoader。不过,我们需要一个堆栈跟踪来确认这一点。
在创建
PropHolder.prop
静态变量时发生。