gpt4 book ai didi

java - Jasypt 加密异常 : Exception in thread "main" java. lang.NoClassDefFoundError: org/jasypt/encryption/StringEncryptor

转载 作者:行者123 更新时间:2023-12-02 01:06:31 30 4
gpt4 key购买 nike

我有简单的java控制台应用程序,我在其中使用Jasypt1.9.2来加密数据库连接字符串。代码在 Eclipse 中运行得很好,但是导出为 Jar 的应用程序会出现此错误 enter image description here

这是我的简单主类:

    public static void main (String args[])
{
try {


GetConnection config = new GetConnection();
out = config.getLogFile();
System.out.println("Start");
Interface.writeLine(out, "Start");

while (true) {
new Interface().ProcessProcedure();
new Interface().ProcessKTP();
new Interface().TransferToPRF();
System.out.println("End");



Thread.sleep(90000);
}



}
catch (java.lang.Exception ex) {
System.out.println("Error:"+ex);
}
}

这是我的 GetConnection 类

public Connection getSql(BufferedWriter out){

try{


StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();

prop = new EncryptableProperties(encryptor); //--fOR ENCRYPTED PASSWORD


String fileName = System.getProperty("user.dir") + "\\configuration.properties";
InputStream is = new FileInputStream(fileName);



//InputStream inputStream;



if (is != null) {
prop.load(is);
} else {
throw new FileNotFoundException("Configuration property not found");
}


String Driver = prop.getProperty("sqlserver.driver");
String url = prop.getProperty("sqlserver.durl");
String id = prop.getProperty("sqlserver.uid");
key = "123"
encryptor.setPassword(key);
String sqlpass = prop.getProperty("sqlserver.pass").trim();


Class.forName(Driver).newInstance();
Connection conMSSQL = DriverManager.getConnection (url,id,sqlpass);




if(conMSSQL != null && conMSSQL.isValid(0)) {

GetConnection.writeLine(out,"Connection established");


}
return conMSSQL;
}
catch( Exception ex ){

GetConnection.writeLine(out,"Exception at Kondor connection");
GetConnection.writeLine(out,ex.getMessage());


return null;
}


}

我已检查并验证了 Jasypt1.9.2.jar 条目的类路径。请帮忙。

最佳答案

NoClassDefFoundError 表示 JVM 尝试访问某个类,但没有找到它。

您已将项目导出到 JAR 文件,但未导出其依赖项。

从 eclipse 导出时选择packagerepack 选项。

这会将依赖项添加到导出的 JAR 文件中。

关于java - Jasypt 加密异常 : Exception in thread "main" java. lang.NoClassDefFoundError: org/jasypt/encryption/StringEncryptor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59979797/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com