我面對的問題是,每次運行代碼時都不會發生NoClassDefFoundError。它有時會發生。在某種程度上,我的意思是,在服務器上部署戰爭2-3次後(.ie卸載先前的戰爭,現在安裝然後開始新的戰爭),在特定的服務器上調用(.ie爲特定的Web服務),它使用generateHash類的方法Util給出下面,我得到這個類的NoclassDefFoundError TestJNIUtil。Java - NoClassDefinitionFoundError for Java Class
所以每次出現此錯誤時,我不得不停止Java和服務器的所有服務,然後重新啓動again.Due他們隨機出現這個錯誤,我無法找到這個問題背後的原因。
請幫我解決這個問題。
注:春天在項目中使用。
public class Util {
public static String generateHash(String a, String b) throws MyException{
logger.info("In generateHash()");
if(!StringUtil.isNullOrEmpty(a) && !StringUtil.isNullOrEmpty(b)){
String hash = TestJNIUtil.getHashCode(a, b);
logger.info("Inputs used a and b : " + a + " , " + b);
logger.info("HashCode Generated : " + hash);
logger.info("Out generateHash()");
return hash;
}
logger.info("Out generateHash()");
return null;
}
}
public class TestJNIUtil{
private static MyLogger logger = MyLoggingImpl.getLogger(TestJNI.class);
static {
logger.info("In static block to load DLL.");
String dllPath = System.getenv(MyConstants.JNI_LIB);
if(!StringUtil.isNullOrEmpty(dllPath)){
logger.info("Loading MyJni.dll & libeay32.dll from Classpath.");
libPath = System.getenv("JNI_LIB");
logger.info("Library Path Used for Jni: " + libPath);
System.load(libPath + "\\MyJni.dll");
logger.info("Loaded MyJni.dll Successfully.");
System.load(libPath + "\\libeay32.dll");
logger.info("Loaded libeay32.dll Successfully.");
}else{
logger.info("add JNI_LIB environment variable to load DLL.");
}
logger.info("Out static block to load DLL.");
}
public static String getHashCode(String a, String b)
throws MyException {
logger.info("In getHashCode().");
String hashCode = null;
try {
if (a and b are not null) {
// Call native code for hash code generation.
hashCode = MyJni.generateHash(a, b);
logger.info("Hash Code Generated : " + hashCode);
} else {
//throw MyException
}
} catch (MyException e) {
//log and then throw MyException
}
if (StringUtil.isNullOrEmpty(hashCode)) {
//log and then throw MyException
}
logger.info("Out getHashCode().");
return hashCode;
}
}
public class MyJNI {
public static native String generateHash(String a, String b);
}
都在同一個戰/罐的TestJNIUtil和的Util? –
是的所有這一切都在同一場戰爭 –